问题
I have a parent node "posts" and i need to get the number of children under this parent.
- I delete the whole "posts" node itself.
- Re-create "posts" with 1 children inside of it.
- using .getChildrenCount() of the snapshot from databaseRef.children("posts")
- .getChildrenCount() return 12 (suppose to be 1 at this point of time)
- 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