Skip to content

Commit cc17bc9

Browse files
committed
format
1 parent 203e943 commit cc17bc9

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

packages/firestore/src/remote/bloom_filter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export class BloomFilter {
7575
this.bitCountInInteger = Integer.fromNumber(this.bitCount);
7676
}
7777

78+
isEmpty(): boolean {
79+
return this.bitCount === 0;
80+
}
81+
7882
// Calculate the ith hash value based on the hashed 64bit integers,
7983
// and calculate its corresponding bit index in the bitmap to be checked.
8084
private getBitIndex(num1: Integer, num2: Integer, hashIndex: number): number {

packages/firestore/src/remote/remote_event.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export class RemoteEvent {
4444
*/
4545
readonly targetChanges: Map<TargetId, TargetChange>,
4646
/**
47-
* A set of targets that is known to be inconsistent. Listens for these
48-
* targets should be re-established without resume tokens.
47+
* A map of targets that is known to be inconsistent, and the purpose for
48+
* re-listening. Listens for these targets should be re-established without
49+
* resume tokens.
4950
*/
5051
readonly targetMismatches: SortedMap<TargetId, TargetPurpose>,
5152
/**

packages/firestore/src/remote/remote_store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,10 @@ function raiseWatchSnapshot(
611611
// Mark the target we send as being on behalf of an existence filter
612612
// mismatch, but don't actually retain that in listenTargets. This ensures
613613
// that we flag the first re-listen this way without impacting future
614-
// listens of this target (that might happen e.g. on reconnect).
614+
// listens of this target (that might happen e.g. on reconnect). The target
615+
// purpose will be `ExistenceFilterMismatchBloom` if there is a bloom filter
616+
// but it yield false positive result, otherwise, it will be set to
617+
// `ExistenceFilterMismatch`.
615618
const requestTargetData = new TargetData(
616619
targetData.target,
617620
targetId,

packages/firestore/src/remote/serializer.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ export function toListenRequestLabels(
10081008
serializer: JsonProtoSerializer,
10091009
targetData: TargetData
10101010
): ProtoApiClientObjectMap<string> | null {
1011-
const value = toLabel(serializer, targetData.purpose);
1011+
const value = toLabel(targetData.purpose);
10121012
if (value == null) {
10131013
return null;
10141014
} else {
@@ -1018,10 +1018,7 @@ export function toListenRequestLabels(
10181018
}
10191019
}
10201020

1021-
export function toLabel(
1022-
serializer: JsonProtoSerializer,
1023-
purpose: TargetPurpose
1024-
): string | null {
1021+
export function toLabel(purpose: TargetPurpose): string | null {
10251022
switch (purpose) {
10261023
case TargetPurpose.Listen:
10271024
return null;

packages/firestore/src/remote/watch_change.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class WatchChangeAggregator {
285285
private pendingDocumentTargetMapping = documentTargetMap();
286286

287287
/**
288-
* A list of targets with existence filter mismatches. These targets are
288+
* A map of targets with existence filter mismatches. These targets are
289289
* known to be inconsistent and their listens needs to be re-established by
290290
* RemoteStore.
291291
*/
@@ -430,15 +430,16 @@ export class WatchChangeAggregator {
430430
if (currentSize !== expectedCount) {
431431
// Apply bloom filter to identify and mark removed documents.
432432
const status = this.applyBloomFilter(watchChange, currentSize);
433+
433434
if (status !== BloomFilterApplicationStatus.Success) {
434435
// If bloom filter application fails, we reset the mapping and
435436
// trigger re-run of the query.
436437
this.resetTarget(targetId);
438+
437439
const purpose: TargetPurpose =
438440
status === BloomFilterApplicationStatus.FalsePositive
439441
? TargetPurpose.ExistenceFilterMismatchBloom
440442
: TargetPurpose.ExistenceFilterMismatch;
441-
442443
this.pendingTargetResets = this.pendingTargetResets.insert(
443444
targetId,
444445
purpose
@@ -469,10 +470,6 @@ export class WatchChangeAggregator {
469470
hashCount = 0
470471
} = unchangedNames;
471472

472-
if (bitmap.length === 0) {
473-
return BloomFilterApplicationStatus.Skipped;
474-
}
475-
476473
let normalizedBitmap: Uint8Array;
477474
try {
478475
normalizedBitmap = normalizeByteString(bitmap).toUint8Array();
@@ -502,6 +499,10 @@ export class WatchChangeAggregator {
502499
return BloomFilterApplicationStatus.Skipped;
503500
}
504501

502+
if (bloomFilter.isEmpty()) {
503+
return BloomFilterApplicationStatus.Skipped;
504+
}
505+
505506
const removedDocumentCount = this.filterRemovedDocuments(
506507
watchChange.targetId,
507508
bloomFilter

packages/firestore/test/unit/remote/remote_event.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ describe('RemoteEvent', () => {
459459
event = aggregator.createRemoteEvent(version(3));
460460
expect(event.documentUpdates.size).to.equal(0);
461461
expect(event.targetMismatches.size).to.equal(1);
462+
expect(event.targetMismatches.get(1)).to.equal(
463+
TargetPurpose.ExistenceFilterMismatch
464+
);
462465
expect(event.targetChanges.size).to.equal(1);
463466

464467
const expected = updateMapping(
@@ -499,6 +502,9 @@ describe('RemoteEvent', () => {
499502
const event = aggregator.createRemoteEvent(version(3));
500503
expect(event.documentUpdates.size).to.equal(1);
501504
expect(event.targetMismatches.size).to.equal(1);
505+
expect(event.targetMismatches.get(1)).to.equal(
506+
TargetPurpose.ExistenceFilterMismatch
507+
);
502508
expect(event.targetChanges.get(1)!.current).to.be.false;
503509
});
504510

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ abstract class TestRunner {
11041104
"Actual listen request doesn't have a 'goog-listen-tags'"
11051105
);
11061106
expect(labels['goog-listen-tags']).to.equal(
1107-
toLabel(this.serializer, expected.targetPurpose)
1107+
toLabel(expected.targetPurpose)
11081108
);
11091109
}
11101110

0 commit comments

Comments
 (0)