Skip to content

Commit ef1a6e9

Browse files
committed
resolve comments
1 parent 89fb871 commit ef1a6e9

File tree

4 files changed

+11
-165
lines changed

4 files changed

+11
-165
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/TargetData.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.firebase.firestore.model.SnapshotVersion;
2222
import com.google.firebase.firestore.remote.WatchStream;
2323
import com.google.protobuf.ByteString;
24+
import java.util.Objects;
2425

2526
/** An immutable set of metadata that the store will need to keep track of for each target. */
2627
public final class TargetData {
@@ -93,7 +94,7 @@ public TargetData withSequenceNumber(long sequenceNumber) {
9394
snapshotVersion,
9495
lastLimboFreeSnapshotVersion,
9596
resumeToken,
96-
expectedCount);
97+
/* expectedCount= */ null);
9798
}
9899

99100
/** Creates a new target data instance with an updated resume token and snapshot version. */
@@ -110,7 +111,7 @@ public TargetData withResumeToken(ByteString resumeToken, SnapshotVersion snapsh
110111
}
111112

112113
/** Creates a new target data instance with an updated expected count. */
113-
public TargetData withExpectedCount(Integer expectedCount) {
114+
public TargetData withExpectedCount(@Nullable Integer expectedCount) {
114115
return new TargetData(
115116
target,
116117
targetId,
@@ -188,7 +189,7 @@ public boolean equals(Object o) {
188189
&& snapshotVersion.equals(targetData.snapshotVersion)
189190
&& lastLimboFreeSnapshotVersion.equals(targetData.lastLimboFreeSnapshotVersion)
190191
&& resumeToken.equals(targetData.resumeToken)
191-
&& expectedCount == targetData.expectedCount;
192+
&& Objects.equals(expectedCount, targetData.expectedCount);
192193
}
193194

194195
@Override
@@ -200,7 +201,7 @@ public int hashCode() {
200201
result = 31 * result + snapshotVersion.hashCode();
201202
result = 31 * result + lastLimboFreeSnapshotVersion.hashCode();
202203
result = 31 * result + resumeToken.hashCode();
203-
result = 31 * result + (expectedCount != null ? expectedCount.hashCode() : 0);
204+
result = 31 * result + Objects.hashCode(expectedCount);
204205
return result;
205206
}
206207

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/RemoteSerializer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ public Target encodeTarget(TargetData targetData) {
499499
builder.setResumeToken(targetData.getResumeToken());
500500
}
501501

502-
if (targetData.getExpectedCount() != null) {
502+
if (targetData.getExpectedCount() != null
503+
&& (!targetData.getResumeToken().isEmpty()
504+
|| targetData.getSnapshotVersion().compareTo(SnapshotVersion.NONE) > 0)) {
503505
builder.setExpectedCount(Int32Value.newBuilder().setValue(targetData.getExpectedCount()));
504506
}
505507

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/RemoteStore.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,10 @@ private void sendWatchRequest(TargetData targetData) {
372372
if (!targetData.getResumeToken().isEmpty()
373373
|| targetData.getSnapshotVersion().compareTo(SnapshotVersion.NONE) > 0) {
374374
int expectedCount = this.getRemoteKeysForTarget(targetData.getTargetId()).size();
375-
TargetData newTargetData = targetData.withExpectedCount(expectedCount);
376-
watchStream.watchQuery(newTargetData);
377-
} else {
378-
watchStream.watchQuery(targetData);
375+
targetData = targetData.withExpectedCount(expectedCount);
379376
}
377+
378+
watchStream.watchQuery(targetData);
380379
}
381380

382381
/**

0 commit comments

Comments
 (0)