Firebase數(shù)據(jù)庫(kù)快速啟動(dòng)處理計(jì)數(shù)的方式安全嗎?我想為文章“喜歡”創(chuàng)建一個(gè)增量字段。我指的是這一聯(lián)系:https:/Firebase.google.com/docs/database/android/Save-data#Save_data_as_事務(wù)在該示例中,有用于增量字段的代碼: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);}但是,如果用戶已經(jīng)/不喜歡這篇文章,我如何確定呢?在這個(gè)例子中,用戶(黑客)可能會(huì)像這樣清除整個(gè)星圖,它無論如何都會(huì)保存:p.stars = new HashMap<>();這將破壞其他用戶已經(jīng)喜歡它的邏輯。我甚至不認(rèn)為你能為這個(gè)制定規(guī)則,特別是對(duì)于“減少計(jì)數(shù)”行動(dòng)。有什么幫助嗎,建議?
- 2 回答
- 0 關(guān)注
- 322 瀏覽
添加回答
舉報(bào)
0/150
提交
取消