首页 > 解决方案 > 最大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");
 });

标签: node.jsfirebase-realtime-databasegoogle-cloud-functionsfirebase-securityfirebase-admin

解决方案


推荐阅读