我试图从本地保存的musicbrainz数据库中随机获取100K歌曲。我是编程的新手,想知道我的电脑减速的原因是什么(可能是ram填充)。我在虚拟机上运行ubuntu。请提出一些更改,以便我可以在运行后进入睡眠状态。
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
for (UserInfo profile : user.getProviderData()) {
// Id of the provider (ex: google.com)
String providerId = profile.getProviderId();
// UID specific to the provider
String uid = profile.getUid();
// Name, email address, and profile photo Url
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl();
};
}
感谢您抽出时间阅读此代码。 另外,如果你们有任何建议让我改进我的编码风格,我很乐意学习。 再次感谢你。
答案 0 :(得分:0)
我的预感是,你从帽子中取出的身份证最终会徘徊到身份证不存在的地区。这意味着您将运行一个永久长*循环,这是低效的。
而不是这种方法,为什么不将数据库中的ID从已知的数据库中拉出来,而不是选择?
你可以用这个完成。我借用了一个列表展平操作{{3}},这将使ID列表变得简单。
cur1.execute("select id from Song")
result = cur1.fetchall()
result = [item for sublist in result for item in sublist]
# result holds the total amount of elements in your Song DB
# use len() to get the total number of rows from here
rnumbers = random.sample(result, 100000-len(result))
然后您可以摆脱while循环,因为您可以保证拥有实际存在于数据库中的ID。