Firebase数据库快速启动处理计数的方式安全吗?我想为文章“喜欢”创建一个增量字段。我指的是这一联系:https:/Firebase.google.com/docs/database/android/Save-data#Save_data_as_事务在该示例中,有用于增量字段的代码:if (p.stars.containsKey(getUid())) {
// Unstar the post and remove self from stars
p.starCount = p.starCount - 1;
p.stars.remove(getUid());} else {
// Star the post and add self to stars
p.starCount = p.starCount + 1;
p.stars.put(getUid(), true);}但是,如果用户已经/不喜欢这篇文章,我如何确定呢?在这个例子中,用户(黑客)可能会像这样清除整个星图,它无论如何都会保存:p.stars = new HashMap<>();这将破坏其他用户已经喜欢它的逻辑。我甚至不认为你能为这个制定规则,特别是对于“减少计数”行动。有什么帮助吗,建议?
2 回答
- 2 回答
- 0 关注
- 310 浏览
添加回答
举报
0/150
提交
取消