node.js - 最大cpu使用率大表
问题描述
我有一个拥有 100 万用户的数据库,我想根据他们的分数对他们进行排序。当我尝试对它们进行排序时,即使我使用索引,它也会使用 100% 的 cpu,并且所有内容都会冻结 1 分钟。我应该使用多个数据库来解决这个问题吗?
我不希望查询单独使用所有处理器?
我的数据库规则。
"userlist": {
".read": true,
".indexOn": ["coin", "fcb_coin","name","rateus","guestid","email"],
"$uid": {
".write": "auth.uid==$uid",
".read": "true",
}
},
我的数据库结构
userlist:
uid:
name:
email:
fcb_coin:
device_type
facebookid:
deviceid:
我的 Firebase 云功能
exports.createmyrankings = functions.https.onRequest((request, response) => {
var db = admin.database().ref();
db.child("userlist").orderByChild('fcb_coin').startAt(-999999999999).limitToFirst(50).once('value', (snapshot) => {
let mycount=1;
snapshot.forEach((userSnap) => {
if(mycount<=50){
snapshot.ref.parent.child('worldtop').child(mycount).remove();
snapshot.ref.parent.child('worldtop').child(mycount).child(userSnap.child('fcb_ids').val()).child('coin').set(userSnap.child('coin').val());
snapshot.ref.parent.child('worldtop').child(mycount).child(userSnap.child('fcb_ids').val()).child('name').set(userSnap.child('name').val());
snapshot.ref.parent.child('worldtop').child(mycount).child(userSnap.child('fcb_ids').val()).child('fcb_ids').set(userSnap.child('fcb_ids').val());
mycount=mycount+1;
}
});
});
response.send("ranking Is created");
});
解决方案
推荐阅读
- java - 如何在 Typescript 中获取 Java Map 的值
- python - 如何从子流程获取实时输出流?
- r - 使用字符串输出作为数据框变量名的一部分
- c++ - Sublime Text 3 中的“错误文件描述符”是什么意思?
- javascript - Angular App 在将一个视图导航到另一个具有高负载响应的 HTTP 请求时冻结
- amazon-web-services - AWS RDS 主副本和只读副本垂直扩展
- angular - ngAfterViewChecked 还不够晚
- json - 使用 jq 和 map 将带有嵌套对象的 JSON 对象转换为 Name=Value 格式
- csv - 批处理文件复制 CSV 文件中的列
- django - Django,将图像保存到 ImageField 保存空图像