Я использую транзакцию облачного пожарного хранилища для редактирования некоторых данных в облачном пожарном хранилище, но я получил эту ошибку:
FirebaseFirestoreException: Every document read in a transaction must also be written.
Я пересмотрел случаи, которые могут привести к сбою транзакции в учебнике Firebase, но яничего не нашел об этой ошибке.это мой код:
if (getCurrentPlayer(player1Uid) == 2) {
Log.v("limitingChallenges", "current player is 2");
DocumentSnapshot snapshotForPlayer2 = transaction.get(player2Reference);
if (snapshotForPlayer2.getLong("totalChallengesNo") != null) {
totalChallengesNo = snapshotForPlayer2.getLong("totalChallengesNo");
}
if (snapshotForPlayer2.getLong("todayChallengesNo") != null) {
todayChallengesNo = snapshotForPlayer2.getLong("todayChallengesNo");
}
if (player1Score == player2Score) {
if (snapshotForPlayer2.getLong("noOfDraws") != null)
noOfDraws = snapshotForPlayer2.getLong("noOfDraws");
newPoints = snapshotForPlayer2.getLong("points") + (long) drawChallengePoints;
newNoOfDraws = noOfDraws + (long) 1;
transaction.update(player2Reference, "points", newPoints);
transaction.update(player2Reference, "totalChallengesNo", totalChallengesNo + 1);
transaction.update(player2Reference, "todayChallengesNo", todayChallengesNo + 1);
if (totalChallengesNo != 0) {
transaction.update(player2Reference, "noOfDraws", newNoOfDraws);
} else {
transaction.update(player2Reference, "noOfDraws", 1);
transaction.update(player2Reference, "noOfWins", 0);
transaction.update(player2Reference, "noOfLoses", 0);
}
return null;
} else if (player2Score > player1Score) {
if (snapshotForPlayer2.getLong("noOfWins") != null)
noOfWins = snapshotForPlayer2.getLong("noOfWins");
newPoints = snapshotForPlayer2.getLong("points") + (long) wonChallengePoints;
newNoOfWins = noOfWins + (long) 1;
transaction.update(player2Reference, "points", newPoints);
transaction.update(player2Reference, "totalChallengesNo", totalChallengesNo + 1);
transaction.update(player2Reference, "todayChallengesNo", todayChallengesNo + 1);
if (totalChallengesNo != 0) {
transaction.update(player2Reference, "noOfWins", newNoOfWins);
} else {
transaction.update(player2Reference, "noOfDraws", 0);
transaction.update(player2Reference, "noOfWins", 1);
transaction.update(player2Reference, "noOfLoses", 0);
}
return null;
} else {
if (snapshotForPlayer2.getLong("noOfLoses") != null)
noOfLoses = snapshotForPlayer2.getLong("noOfLoses");
newNoOfLoses = noOfLoses + (long) 1;
transaction.update(player2Reference, "totalChallengesNo", totalChallengesNo + 1);
transaction.update(player2Reference, "todayChallengesNo", todayChallengesNo + 1);
if (totalChallengesNo != 0) {
transaction.update(player2Reference, "noOfLoses", newNoOfLoses);
} else {
transaction.update(player2Reference, "noOfDraws", 0);
transaction.update(player2Reference, "noOfWins", 0);
transaction.update(player2Reference, "noOfLoses", 1);
}
}
} else if (getCurrentPlayer(player1Uid) == 1) {
DocumentSnapshot snapshotForPlayer1 = transaction.get(player1Reference);
if (snapshotForPlayer1.getLong("todayChallengesNo") != null) {
todayChallengesNo = snapshotForPlayer1.getLong("todayChallengesNo");
}
transaction.update(player2Reference, "totalChallengesNo", totalChallengesNo + 1);
transaction.update(player2Reference, "todayChallengesNo", todayChallengesNo + 1);
Log.v("limitingChallenges", "current player is 1"
+ " , new todayChallengesNo is " + todayChallengesNo + 1);
}
return todayChallengesNo + 1;
}
}).addOnSuccessListener(new OnSuccessListener<Long>() {
@Override
public void onSuccess(Long aLong) {
Log.v("limitingChallenges", "onSuccess , aLong is : " + aLong.toString());
if (aLong > 3) {
Toast.makeText(context, "يمكنك لعب " + (dailyChallengesNumber - aLong) + " تحديات فقط اليوم بعد هذا التحدى", Toast.LENGTH_SHORT).show();
} else if (aLong == 2) {
Toast.makeText(context, "يمكنك لعب " + " تحديان فقط اليوم بعد هذا التحدى", Toast.LENGTH_SHORT).show();
} else if (aLong == 1) {
Toast.makeText(context, "يمكنك لعب " + " تحدي واحد فقط اليوم بعد هذا التحدى", Toast.LENGTH_SHORT).show();
} else if (aLong < 1) {
Toast.makeText(context, "لا يمكنك لعب تحديات أخرى هذا اليوم يمكنك العودة غدا للعب تحديات جديدة", Toast.LENGTH_SHORT).show();
}
setSavedTodayChallengesNo(context, aLong);
}
})
Я пересматривал код более одного раза, но не могу найти проблему, и сообщение об ошибке недостаточно очевидно, чтобы определить, в чем именно проблема