Firebase 事务中的字段发生意外更改



我在某些但不是全部的数据字段中得到了一个奇怪的更新,其中包含Firebase事务。

有一个火种风格的应用程序,我只查看未来日期的"帖子"。我可以在我的数据库中看到我的测试帖子有一个未来的日期并在应用程序中打开。如果日期是过去的日期,则不会按预期打开。我的问题是,在我执行滑动并触发以下代码后,日期字段似乎已更新为半随机日期,该日期不是我的计算机或设备上的日期,而始终是某个月的 28 日。据我所知,下面的代码不应该更新日期,但即使是日志语句也显示已更新的日期

public void swipeReject(String postId) {
        getPostRef(postId);
        onSwiped(globalPostRef, FALSE);
    }
    private void getPostRef(String postId){
        mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
        globalPostRef = mFirebaseDatabaseReference.child("messages").child(postId);
    }
    private void onSwiped(DatabaseReference postRef, Boolean accepted) {
        final Boolean accept = accepted;
        postRef.runTransaction(new Transaction.Handler() {
            @Override
            public Transaction.Result doTransaction(MutableData mutableData) {
                PostMessage p = mutableData.getValue(PostMessage.class);
                if (p == null) {
                    return Transaction.success(mutableData);
                }
                Log.e("date", String.valueOf(p.getDate()));
                if (p.votes.containsKey(mFirebaseUser.getUid())) {
                    // This shouldn't happen
                } else {
                    if (accept){
                        p.votes.put(mFirebaseUser.getUid(), "upvote");
                        p.upVoteCount = p.upVoteCount + 1;
                    }else{
                        p.votes.put(mFirebaseUser.getUid(), "downvote");
                        p.downVoteCount = p.downVoteCount + 1;
                    }
                }
                // Set value and report transaction success
                mutableData.setValue(p);
                return Transaction.success(mutableData);
            }
            @Override
            public void onComplete(DatabaseError databaseError, boolean b,
                                   DataSnapshot dataSnapshot) {
                // Transaction completed
                if (databaseError != null){
                    Log.e(TAG, "postTransaction:onComplete:" + databaseError);
                }
            }
        });

在此之前的代码只是从数据库读取数据,无需写入操作。我不知道这个字段正在更新?

我可以做些什么来调试它?

事实证明,我的代码没有任何问题。错误出现在我的数据库值中。虽然自纪元以来的毫秒是正确的,但还有另一个日期字段记录了不正确的年份。一旦更新,一切都有意义。

最新更新