相关疑难解决方法(0)

Firebase数据库快速入门处理计数的方式是否安全?

我想为文章喜欢创建一个增量字段.

我指的是以下链接:https://firebase.google.com/docs/database/android/save-data#save_data_as_transactions

在示例中,有增量字段的代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

但是,我怎么能确定用户是否已经喜欢/不喜欢这篇文章?

在这个例子中,用户(黑客)也可以像这样清除整个星图,它会保存:

p.stars = new HashMap<>();
Run Code Online (Sandbox Code Playgroud)

它会破坏已经喜欢它的其他用户的逻辑.

我甚至认为你不能为此制定规则,尤其是"减少计数"行动.

任何帮助,建议?

android firebase firebase-realtime-database

16
推荐指数
1
解决办法
5396
查看次数