Firebase warning: Using an unspecified index

2019-04-19 05:40发布

I get this warning message from Firebase for every single orderByChild I used in my queries from JavaScript:

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "" at /tables to your security rules for better performance

So far my queries ran quite fast so I think it is not necessary to include the indexOn. Just wondering what are the negative impacts?

Also, how do I actually disable the warnings as they are quite irritating when I am debugging.

3条回答
在下西门庆
2楼-- · 2019-04-19 05:50

Firebase provides powerful tools for ordering and querying your data. Indexing can improve the performance of our queries. consider a table called dinosaur has some data like:

{
  "lambeosaurus": {
    "height" : 2.1,
    "length" : 12.5,
    "weight": 5000
  },
  "stegosaurus": {
    "height" : 4,
    "length" : 9,
    "weight" : 2500
  }
}

You need to (search) order the dinosaurs height, and length, but never by weight. so you need to set a rules for dinosaur table like:

"rules": {
  "dinosaurs": {
    ".indexOn": ["height", "length"]
  }
}

By telling Firebase this information, Firebase can use this .indexOn to optimize our queries for height and length. Then we maintained Firebase security for querying our data and improve the performance of our queries as well.

查看更多
姐就是有狂的资本
3楼-- · 2019-04-19 06:07

If you are on development phase, you won't feel the difference. But as your data grows indexing helps making your queries much faster.

Read this to know more on advantages of indexing. https://firebase.google.com/docs/database/security/indexing-data

As far as I know to disable the warnings, you have to edit firebase source code. Is there someway to disable all firebase logging to console?

查看更多
淡お忘
4楼-- · 2019-04-19 06:12

As the others have said: if you don't define an index, all filtering happens client-side. This is likely fine during initial development, but as you add more data it becomes more and more wasteful.

To fix the problem, define the correct index in your Firebase Database rules. You can modify the rules in the Database panel in your project's Firebase console. See defining data indexes in the Firebase documentation.

Is there any way for me to observe what has changed through the indexing?

  1. After you define the correct index, the warning will disappear from your JavaScript console.
  2. In addition you can watch the traffic between the Firebase client and the server in the Network tab of your browser's developer tools. Before you define the correct index, you'll see that the Firebase client downloads all data in the location (since it performs the filtering locally). After you define the correct index, you'll see that the Firebase client only downloads the data that matching the query.
查看更多
登录 后发表回答