Skip to content

Commit 40dea6a

Browse files
Don't update query target metadata for updates (#1063)
1 parent 276ebe3 commit 40dea6a

File tree

6 files changed

+36
-28
lines changed

6 files changed

+36
-28
lines changed

packages/firestore/src/local/indexeddb_query_cache.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ export class IndexedDbQueryCache implements QueryCache {
8787
});
8888
}
8989

90-
setLastRemoteSnapshotVersion(
90+
setTargetsMetadata(
9191
transaction: PersistenceTransaction,
92-
snapshotVersion: SnapshotVersion
92+
highestListenSequenceNumber: number,
93+
lastRemoteSnapshotVersion?: SnapshotVersion
9394
): PersistencePromise<void> {
9495
return this.retrieveMetadata(transaction).next(metadata => {
95-
metadata.lastRemoteSnapshotVersion = snapshotVersion.toTimestamp();
96+
metadata.highestListenSequenceNumber = highestListenSequenceNumber;
97+
if (lastRemoteSnapshotVersion) {
98+
metadata.lastRemoteSnapshotVersion = lastRemoteSnapshotVersion.toTimestamp();
99+
}
96100
return this.saveMetadata(transaction, metadata);
97101
});
98102
}
@@ -114,15 +118,7 @@ export class IndexedDbQueryCache implements QueryCache {
114118
transaction: PersistenceTransaction,
115119
queryData: QueryData
116120
): PersistencePromise<void> {
117-
return this.saveQueryData(transaction, queryData).next(() => {
118-
return this.retrieveMetadata(transaction).next(metadata => {
119-
if (this.updateMetadataFromQueryData(queryData, metadata)) {
120-
return this.saveMetadata(transaction, metadata);
121-
} else {
122-
return PersistencePromise.resolve();
123-
}
124-
});
125-
});
121+
return this.saveQueryData(transaction, queryData);
126122
}
127123

128124
removeQueryData(

packages/firestore/src/local/local_store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,9 @@ export class LocalStore {
605605
' < ' +
606606
lastRemoteVersion
607607
);
608-
return this.queryCache.setLastRemoteSnapshotVersion(
608+
return this.queryCache.setTargetsMetadata(
609609
txn,
610+
/*highestSequenceNumber=*/ 0,
610611
remoteVersion
611612
);
612613
});

packages/firestore/src/local/memory_query_cache.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ export class MemoryQueryCache implements QueryCache {
6969
return PersistencePromise.resolve(nextTargetId);
7070
}
7171

72-
setLastRemoteSnapshotVersion(
72+
setTargetsMetadata(
7373
transaction: PersistenceTransaction,
74-
snapshotVersion: SnapshotVersion
74+
highestListenSequenceNumber: number,
75+
lastRemoteSnapshotVersion?: SnapshotVersion
7576
): PersistencePromise<void> {
76-
this.lastRemoteSnapshotVersion = snapshotVersion;
77+
if (lastRemoteSnapshotVersion) {
78+
this.lastRemoteSnapshotVersion = lastRemoteSnapshotVersion;
79+
}
7780
return PersistencePromise.resolve();
7881
}
7982

packages/firestore/src/local/query_cache.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ export interface QueryCache extends GarbageSource {
5151
): PersistencePromise<SnapshotVersion>;
5252

5353
/**
54-
* Set the snapshot version representing the last consistent snapshot received
55-
* from the backend. (see getLastRemoteSnapshotVersion() for more details).
54+
* Set the highest listen sequence number and optionally updates the
55+
* snapshot version of the last consistent snapshot received from the backend
56+
* (see getLastRemoteSnapshotVersion() for more details).
5657
*
57-
* @param snapshotVersion The new snapshot version.
58+
* @param highestListenSequenceNumber The new maximum listen sequence number.
59+
* @param lastRemoteSnapshotVersion The new snapshot version. Optional.
5860
*/
59-
setLastRemoteSnapshotVersion(
61+
setTargetsMetadata(
6062
transaction: PersistenceTransaction,
61-
snapshotVersion: SnapshotVersion
63+
highestListenSequenceNumber: number,
64+
lastRemoteSnapshotVersion?: SnapshotVersion
6265
): PersistencePromise<void>;
6366

6467
/**

packages/firestore/test/unit/local/query_cache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,14 @@ function genericQueryCacheTests(): void {
325325
expect(await otherCache.allocateTargetId()).to.deep.equal(50);
326326
});
327327

328-
it('can get / set lastRemoteSnapshotVersion', async () => {
328+
it('can get / set targets metadata', async () => {
329329
expect(await cache.getLastRemoteSnapshotVersion()).to.deep.equal(
330330
SnapshotVersion.MIN
331331
);
332332

333333
// Can set the snapshot version.
334334
return cache
335-
.setLastRemoteSnapshotVersion(version(42))
335+
.setTargetsMetadata(/* highestListenSequenceNumber= */ 0, version(42))
336336
.then(async () => {
337337
expect(await cache.getLastRemoteSnapshotVersion()).to.deep.equal(
338338
version(42)

packages/firestore/test/unit/local/test_query_cache.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,16 @@ export class TestQueryCache {
132132
});
133133
}
134134

135-
setLastRemoteSnapshotVersion(version: SnapshotVersion): Promise<void> {
136-
return this.persistence.runTransaction(
137-
'setLastRemoteSnapshotVersion',
138-
true,
139-
txn => this.cache.setLastRemoteSnapshotVersion(txn, version)
135+
setTargetsMetadata(
136+
highestListenSequenceNumber: number,
137+
lastRemoteSnapshotVersion?: SnapshotVersion
138+
): Promise<void> {
139+
return this.persistence.runTransaction('setTargetsMetadata', true, txn =>
140+
this.cache.setTargetsMetadata(
141+
txn,
142+
highestListenSequenceNumber,
143+
lastRemoteSnapshotVersion
144+
)
140145
);
141146
}
142147
}

0 commit comments

Comments
 (0)