Skip to content

Commit 2a5d3f6

Browse files
Manual merge
1 parent f11a000 commit 2a5d3f6

9 files changed

+62
-131
lines changed

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,7 @@ export class IndexedDbPersistence implements Persistence {
422422
return false;
423423
} else if (updateTimeMs > maxAcceptable) {
424424
log.error(
425-
`Detected an update time that is in the future: ${updateTimeMs} > ${
426-
maxAcceptable
427-
}`
425+
`Detected an update time that is in the future: ${updateTimeMs} > ${maxAcceptable}`
428426
);
429427
return false;
430428
}

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ export function createOrUpgradeDb(
6262

6363
if (fromVersion < 2 && toVersion >= 2) {
6464
p = ensureTargetGlobalExists(txn).next(targetGlobal =>
65-
saveTargetCount(txn, targetGlobal)
65+
saveTargetCount(txn, targetGlobal)
6666
);
6767
}
6868

6969
if (fromVersion < 3 && toVersion >= 3) {
70-
createClientMetadataStore(db);
71-
createTargetChangeStore(db);
70+
p = p.next(() => {
71+
createClientMetadataStore(db);
72+
createTargetChangeStore(db);
73+
});
7274
}
7375
return p;
7476
}
@@ -517,11 +519,11 @@ function createQueryCache(db: IDBDatabase): void {
517519
* global singleton.
518520
*/
519521
function saveTargetCount(
520-
txn: SimpleDbTransaction,
521-
metadata: DbTargetGlobal
522+
txn: SimpleDbTransaction,
523+
metadata: DbTargetGlobal
522524
): PersistencePromise<void> {
523525
const globalStore = txn.store<DbTargetGlobalKey, DbTargetGlobal>(
524-
DbTargetGlobal.store
526+
DbTargetGlobal.store
525527
);
526528
const targetStore = txn.store<DbTargetKey, DbTarget>(DbTarget.store);
527529
return targetStore.count().next(count => {
@@ -537,24 +539,24 @@ function saveTargetCount(
537539
* @param {IDBTransaction} txn The version upgrade transaction for indexeddb
538540
*/
539541
function ensureTargetGlobalExists(
540-
txn: SimpleDbTransaction
542+
txn: SimpleDbTransaction
541543
): PersistencePromise<DbTargetGlobal> {
542544
const globalStore = txn.store<DbTargetGlobalKey, DbTargetGlobal>(
543-
DbTargetGlobal.store
545+
DbTargetGlobal.store
544546
);
545547
return globalStore.get(DbTargetGlobal.key).next(metadata => {
546-
if (metadata != null) {
547-
return PersistencePromise.resolve(metadata);
548-
} else {
549-
metadata = new DbTargetGlobal(
550-
/*highestTargetId=*/ 0,
551-
/*lastListenSequenceNumber=*/ 0,
552-
SnapshotVersion.MIN.toTimestamp(),
553-
/*targetCount=*/ 0
554-
);
555-
return globalStore.put(DbTargetGlobal.key, metadata).next(() => metadata);
556-
}
557-
});
548+
if (metadata != null) {
549+
return PersistencePromise.resolve(metadata);
550+
} else {
551+
metadata = new DbTargetGlobal(
552+
/*highestTargetId=*/ 0,
553+
/*lastListenSequenceNumber=*/ 0,
554+
SnapshotVersion.MIN.toTimestamp(),
555+
/*targetCount=*/ 0
556+
);
557+
return globalStore.put(DbTargetGlobal.key, metadata).next(() => metadata);
558+
}
559+
});
558560
}
559561

560562
/**
@@ -642,11 +644,19 @@ export const V1_STORES = [
642644
DbTargetDocument.store
643645
];
644646

645-
const V3_STORES = [DbClientMetadata.store, DbTargetChange.store];
647+
// Visible for testing
648+
export const V2_STORES = V1_STORES;
649+
650+
// Visible for testing
651+
export const V3_STORES = [
652+
...V2_STORES,
653+
DbClientMetadata.store,
654+
DbTargetChange.store
655+
];
646656

647657
/**
648658
* The list of all default IndexedDB stores used throughout the SDK. This is
649659
* used when creating transactions so that access across all stores is done
650660
* atomically.
651661
*/
652-
export const ALL_STORES = [...V1_STORES, ...V3_STORES];
662+
export const ALL_STORES = V3_STORES;

packages/firestore/src/local/memory_persistence.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ export class MemoryPersistence implements Persistence {
5252

5353
private started = false;
5454

55-
<<<<<<< HEAD
5655
constructor(private readonly queue: AsyncQueue) {}
5756

58-
start(): Promise<void> {
59-
=======
6057
async start(): Promise<void> {
6158
// No durable state to read on startup.
62-
>>>>>>> master
6359
assert(!this.started, 'MemoryPersistence double-started!');
6460
this.started = true;
6561
}

packages/firestore/src/util/async_queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export enum TimerId {
5656
* A timer used to update the client metadata in IndexedDb, which is used
5757
* to determine the primary leaseholder.
5858
*/
59-
ClientMetadataRefresh = 'client_metadata_refresh',
59+
ClientMetadataRefresh = 'client_metadata_refresh'
6060
}
6161

6262
/**

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import { expect } from 'chai';
1818
import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
1919
import {
20-
ALL_STORES,
2120
createOrUpgradeDb,
2221
DbTarget,
2322
DbTargetGlobal,
24-
DbTargetGlobalKey
23+
DbTargetGlobalKey,
24+
V1_STORES,
25+
V2_STORES,
26+
V3_STORES
2527
} from '../../../src/local/indexeddb_schema';
2628
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db';
2729
import { PersistencePromise } from '../../../src/local/persistence_promise';
@@ -88,11 +90,10 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
8890
beforeEach(() => SimpleDb.delete(INDEXEDDB_TEST_DATABASE));
8991

9092
it('can install schema version 1', () => {
91-
return withDb(1, db => {
93+
return withDb(1, async db => {
9294
expect(db.version).to.equal(1);
9395
// Version 1 adds all of the stores so far.
94-
expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
95-
return Promise.resolve();
96+
expect(getAllObjectStores(db)).to.have.members(V1_STORES);
9697
});
9798
});
9899

@@ -101,14 +102,21 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
101102
expect(db.version).to.equal(2);
102103
// We should have all of the stores, we should have the target global row
103104
// and we should not have any targets counted, because there are none.
104-
expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
105+
expect(getAllObjectStores(db)).to.have.members(V2_STORES);
105106
// Check the target count. We haven't added any targets, so we expect 0.
106107
return getTargetCount(db).then(targetCount => {
107108
expect(targetCount).to.equal(0);
108109
});
109110
});
110111
});
111112

113+
it('can install schema version 3', () => {
114+
return withDb(3, async db => {
115+
expect(db.version).to.be.equal(3);
116+
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
117+
});
118+
});
119+
112120
it('can upgrade from schema version 1 to 2', () => {
113121
const expectedTargetCount = 5;
114122
return withDb(1, db => {
@@ -126,11 +134,20 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
126134
}).then(() =>
127135
withDb(2, db => {
128136
expect(db.version).to.equal(2);
129-
expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
137+
expect(getAllObjectStores(db)).to.have.members(V2_STORES);
130138
return getTargetCount(db).then(targetCount => {
131139
expect(targetCount).to.equal(expectedTargetCount);
132140
});
133141
})
134142
);
135143
});
144+
145+
it('can upgrade from schema version 2 to 3', () => {
146+
return withDb(2, async () => {}).then(() =>
147+
withDb(3, async db => {
148+
expect(db.version).to.be.equal(3);
149+
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
150+
})
151+
);
152+
});
136153
});

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

Lines changed: 0 additions & 90 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class TestQueryCache {
4343
}
4444

4545
updateQueryData(queryData: QueryData): Promise<void> {
46-
return this.persistence.runTransaction('updateQueryData', txn => {
46+
return this.persistence.runTransaction('updateQueryData', true, txn => {
4747
return this.cache.updateQueryData(txn, queryData);
4848
});
4949
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { doc, path } from '../../util/helpers';
2020

2121
import { describeSpec, specTest } from './describe_spec';
2222
import { client, spec } from './spec_builder';
23-
import {TimerId} from '../../../src/util/async_queue';
23+
import { TimerId } from '../../../src/util/async_queue';
2424

2525
describeSpec('Persistence:', [], () => {
2626
specTest('Local mutations are persisted and re-sent', [], () => {
@@ -223,7 +223,7 @@ describeSpec('Persistence:', [], () => {
223223
.runTimer(TimerId.ClientMetadataRefresh)
224224
.expectPrimaryState(false)
225225
.client(2)
226-
.runTimer(TimerId.ClientMetadataRefresh)
226+
.runTimer(TimerId.ClientMetadataRefresh)
227227
.expectPrimaryState(true)
228228
);
229229
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class SpecBuilder {
209209
becomeVisible(): SpecBuilder {
210210
this.nextStep();
211211
this.currentStep = {
212-
applyClientState: {visibility: 'visible'}
212+
applyClientState: { visibility: 'visible' }
213213
};
214214
return this;
215215
}

0 commit comments

Comments
 (0)