Firebase getChildrenCount() is counting deleted data

青春壹個敷衍的年華 提交于 2019-12-25 07:59:19

问题


I have a parent node "posts" and i need to get the number of children under this parent.

  1. I delete the whole "posts" node itself.
  2. Re-create "posts" with 1 children inside of it.
  3. using .getChildrenCount() of the snapshot from databaseRef.children("posts")
  4. .getChildrenCount() return 12 (suppose to be 1 at this point of time)
  5. Repeat step 1 - 4. This time the .getChildrenCount() return 13.

This above trial shows that the deleted children is still affecting the count. Perhaps there is an internal counter in Firebase that does not get reset when the children was deleted.

Anyone get into this problem before? How to resolve?


回答1:


I have found the solution. There might be some caching on the client side that is causing this issue (in my case, Android as client). The children count is back to normal after i deleted the app from the phone and install then run again.

Hopefully someone from Firebase can explain this behaviour, and maybe tell us how to deal with this. Anyway to clear the cache? This can be a real pain if you are already at production and asking your user to re-install the app simply is not possible.



来源:https://stackoverflow.com/questions/38170187/firebase-getchildrencount-is-counting-deleted-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!