Skip to content

Commit 4b71b13

Browse files
authored
Port "Stop persisting last acknowledged batch ID" from iOS
A straightforward port of firebase/firebase-ios-sdk#2243.
1 parent 604acf3 commit 4b71b13

File tree

4 files changed

+6
-48
lines changed

4 files changed

+6
-48
lines changed

packages/firestore/src/local/indexeddb_mutation_queue.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ export class IndexedDbMutationQueue implements MutationQueue {
117117
streamToken: ProtoByteString
118118
): PersistencePromise<void> {
119119
return this.getMutationQueueMetadata(transaction).next(metadata => {
120-
const batchId = batch.batchId;
121-
assert(
122-
batchId > metadata.lastAcknowledgedBatchId,
123-
'Mutation batchIDs must be acknowledged in order'
124-
);
125-
126-
metadata.lastAcknowledgedBatchId = batchId;
127120
metadata.lastStreamToken = convertStreamToken(streamToken);
128121

129122
return mutationQueuesStore(transaction).put(metadata);
@@ -233,11 +226,7 @@ export class IndexedDbMutationQueue implements MutationQueue {
233226
batchId: BatchId
234227
): PersistencePromise<MutationBatch | null> {
235228
return this.getMutationQueueMetadata(transaction).next(metadata => {
236-
// All batches with batchId <= this.metadata.lastAcknowledgedBatchId have
237-
// been acknowledged so the first unacknowledged batch after batchID will
238-
// have a batchID larger than both of these values.
239-
const nextBatchId =
240-
Math.max(batchId, metadata.lastAcknowledgedBatchId) + 1;
229+
const nextBatchId = batchId + 1;
241230

242231
const range = IDBKeyRange.lowerBound([this.userId, nextBatchId]);
243232
let foundBatch: MutationBatch | null = null;

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ export class DbMutationQueue {
305305
* by the server. All MutationBatches in this queue with batchIds less
306306
* than or equal to this value are considered to have been acknowledged by
307307
* the server.
308+
*
309+
* NOTE: this is deprecated and no longer used by the code.
308310
*/
309311
public lastAcknowledgedBatchId: number,
310312
/**

packages/firestore/src/local/memory_mutation_queue.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { BatchId, ProtoByteString } from '../core/types';
2020
import { DocumentKeySet } from '../model/collections';
2121
import { DocumentKey } from '../model/document_key';
2222
import { Mutation } from '../model/mutation';
23-
import { BATCHID_UNKNOWN, MutationBatch } from '../model/mutation_batch';
23+
import { MutationBatch } from '../model/mutation_batch';
2424
import { emptyByteString } from '../platform/platform';
2525
import { assert } from '../util/assert';
2626
import { primitiveComparator } from '../util/misc';
@@ -44,9 +44,6 @@ export class MemoryMutationQueue implements MutationQueue {
4444
/** Next value to use when assigning sequential IDs to each mutation batch. */
4545
private nextBatchId: BatchId = 1;
4646

47-
/** The highest acknowledged mutation in the queue. */
48-
private highestAcknowledgedBatchId: BatchId = BATCHID_UNKNOWN;
49-
5047
/** The last received stream token from the server, used to acknowledge which
5148
* responses the client has processed. Stream tokens are opaque checkpoint
5249
* markers whose only real value is their inclusion in the next request.
@@ -68,11 +65,6 @@ export class MemoryMutationQueue implements MutationQueue {
6865
streamToken: ProtoByteString
6966
): PersistencePromise<void> {
7067
const batchId = batch.batchId;
71-
assert(
72-
batchId > this.highestAcknowledgedBatchId,
73-
'Mutation batchIDs must be acknowledged in order'
74-
);
75-
7668
const batchIndex = this.indexOfExistingBatchId(batchId, 'acknowledged');
7769
assert(
7870
batchIndex === 0,
@@ -89,7 +81,6 @@ export class MemoryMutationQueue implements MutationQueue {
8981
check.batchId
9082
);
9183

92-
this.highestAcknowledgedBatchId = batchId;
9384
this.lastStreamToken = streamToken;
9485
return PersistencePromise.resolve();
9586
}
@@ -161,10 +152,7 @@ export class MemoryMutationQueue implements MutationQueue {
161152
transaction: PersistenceTransaction,
162153
batchId: BatchId
163154
): PersistencePromise<MutationBatch | null> {
164-
// All batches with batchId <= this.highestAcknowledgedBatchId have been
165-
// acknowledged so the first unacknowledged batch after batchID will have a
166-
// batchID larger than both of these values.
167-
const nextBatchId = Math.max(batchId, this.highestAcknowledgedBatchId) + 1;
155+
const nextBatchId = batchId + 1;
168156

169157
// The requested batchId may still be out of range so normalize it to the
170158
// start of the queue.

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
2121
import { Persistence } from '../../../src/local/persistence';
2222
import { ReferenceSet } from '../../../src/local/reference_set';
2323
import { documentKeySet } from '../../../src/model/collections';
24-
import {
25-
BATCHID_UNKNOWN,
26-
MutationBatch
27-
} from '../../../src/model/mutation_batch';
24+
import { MutationBatch } from '../../../src/model/mutation_batch';
2825
import { emptyByteString } from '../../../src/platform/platform';
2926
import {
3027
expectEqualArrays,
@@ -218,24 +215,6 @@ function genericMutationQueueTests(): void {
218215
expect(notFound).to.be.null;
219216
});
220217

221-
it('getNextMutationBatchAfterBatchId() skips acknowledged batches', async () => {
222-
const batches = await createBatches(3);
223-
expect(
224-
await mutationQueue.getNextMutationBatchAfterBatchId(BATCHID_UNKNOWN)
225-
).to.deep.equal(batches[0]);
226-
227-
await mutationQueue.acknowledgeBatch(batches[0], emptyByteString());
228-
expect(
229-
await mutationQueue.getNextMutationBatchAfterBatchId(BATCHID_UNKNOWN)
230-
).to.deep.equal(batches[1]);
231-
expect(
232-
await mutationQueue.getNextMutationBatchAfterBatchId(batches[0].batchId)
233-
).to.deep.equal(batches[1]);
234-
expect(
235-
await mutationQueue.getNextMutationBatchAfterBatchId(batches[1].batchId)
236-
).to.deep.equal(batches[2]);
237-
});
238-
239218
it('can getAllMutationBatchesAffectingDocumentKey()', async () => {
240219
const mutations = [
241220
setMutation('fob/bar', { a: 1 }),

0 commit comments

Comments
 (0)