Firebase getChildrenCount()计算已删除的数据 [英] Firebase getChildrenCount() is counting deleted data

查看:159
本文介绍了Firebase getChildrenCount()计算已删除的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我删除了整个的父节点posts,我需要得到这个父节点下的子节点的数量。
  2. 重新创建包含1个子元素的posts。
  3. 使用快照的.getChildrenCount()
  4. .getChildrenCount()返回12(假设此时为1)
  5. 重复步骤1 - 4.这一次.getChildrenCount()返回13。

上面的这个试验表明,被删除的子元素仍然影响着计数。也许Firebase中有一个内部计数器,当孩子被删除时,这些内部计数器不会被重置。



任何人都会在之前进入这个问题?如何解决?

解决方案

我找到了解决方案。
在客户端可能有一些缓存导致了这个问题(在我的例子中,Android作为客户端)。
我从电话中删除了应用程序,然后安装然后再次运行,孩子数量恢复正常。



希望有人Firebase可以解释这种行为,也可以告诉我们如何处理这个问题。无论如何清除缓存?如果您已经在生产,并且要求您的用户重新安装应用程序根本是不可能的,这可能是一个真正的痛苦。

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?

解决方案

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.

这篇关于Firebase getChildrenCount()计算已删除的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆