Skip to content

Commit 7e31994

Browse files
Clean up merge conflicts
1 parent 56b15ff commit 7e31994

File tree

4 files changed

+119
-169
lines changed

4 files changed

+119
-169
lines changed

packages/firestore/src/core/sync_engine.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import { assert, fail } from '../util/assert';
3636
import { FirestoreError } from '../util/error';
3737
import * as log from '../util/log';
3838
import { AnyJs, primitiveComparator } from '../util/misc';
39-
import * as objUtils from '../util/obj';
4039
import { ObjectMap } from '../util/obj_map';
4140
import { Deferred } from '../util/promise';
4241
import { SortedMap } from '../util/sorted_map';
@@ -194,13 +193,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
194193
this.syncEngineListener === null,
195194
'SyncEngine already has a subscriber.'
196195
);
197-
<<<<<<< HEAD
198196
this.syncEngineListener = syncEngineListener;
199-
this.limboCollector.addGarbageSource(this.limboDocumentRefs);
200-
=======
201-
this.viewHandler = viewHandler;
202-
this.errorHandler = errorHandler;
203-
>>>>>>> master
204197
}
205198

206199
/**
@@ -501,16 +494,13 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
501494

502495
async rejectListen(targetId: TargetId, err: FirestoreError): Promise<void> {
503496
this.assertSubscribed('rejectListens()');
504-
<<<<<<< HEAD
505497

506498
// PORTING NOTE: Multi-tab only.
507499
this.sharedClientState.trackQueryUpdate(targetId, 'rejected', err);
508500

509-
const limboKey = this.limboKeysByTarget[targetId];
510-
=======
511501
const limboResolution = this.limboResolutionsByTarget[targetId];
512502
const limboKey = limboResolution && limboResolution.key;
513-
>>>>>>> master
503+
514504
if (limboKey) {
515505
// Since this query failed, we won't want to manually unlisten to it.
516506
// So go ahead and remove it from bookkeeping.

packages/firestore/src/local/indexeddb_schema.ts

+24-38
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,21 @@ import { SnapshotVersion } from '../core/snapshot_version';
2929
* Schema Version for the Web client:
3030
* 1. Initial version including Mutation Queue, Query Cache, and Remote Document
3131
* Cache
32-
<<<<<<< HEAD
33-
* 2. Added targetCount to targetGlobal row.
34-
* 3. Multi-Tab Support.
35-
=======
3632
* 2. Used to ensure a targetGlobal object exists and add targetCount to it. No
3733
* longer required because migration 3 unconditionally clears it.
3834
* 3. Dropped and re-created Query Cache to deal with cache corruption related
3935
* to limbo resolution. Addresses
4036
* https://github.com/firebase/firebase-ios-sdk/issues/1548
41-
>>>>>>> master
37+
* 4. Multi-Tab Support.
4238
*/
43-
export const SCHEMA_VERSION = 3;
39+
export const SCHEMA_VERSION = 4;
4440

4541
/**
4642
* Performs database creation and schema upgrades.
4743
*
4844
* Note that in production, this method is only ever used to upgrade the schema
49-
* to SCHEMA_VERSION. Different versions are only used for testing and
50-
* local feature development.
45+
* to SCHEMA_VERSION. Different values of toVersion are only used for testing
46+
* and local feature development.
5147
*/
5248
export function createOrUpgradeDb(
5349
db: IDBDatabase,
@@ -56,14 +52,9 @@ export function createOrUpgradeDb(
5652
toVersion: number
5753
): PersistencePromise<void> {
5854
assert(
59-
<<<<<<< HEAD
60-
fromVersion < toVersion && fromVersion >= 0 && toVersion <= 3,
61-
=======
6255
fromVersion < toVersion && fromVersion >= 0 && toVersion <= SCHEMA_VERSION,
63-
>>>>>>> master
6456
'Unexpected schema upgrade from v${fromVersion} to v{toVersion}.'
6557
);
66-
let p = PersistencePromise.resolve();
6758

6859
if (fromVersion < 1 && toVersion >= 1) {
6960
createOwnerStore(db);
@@ -72,14 +63,21 @@ export function createOrUpgradeDb(
7263
createRemoteDocumentCache(db);
7364
}
7465

75-
<<<<<<< HEAD
76-
if (fromVersion < 2 && toVersion >= 2) {
77-
p = p
78-
.next(() => ensureTargetGlobalExists(txn))
79-
.next(targetGlobal => saveTargetCount(txn, targetGlobal));
66+
// Migration 2 to populate the targetGlobal object no longer needed since
67+
// migration 3 unconditionally clears it.
68+
69+
let p = PersistencePromise.resolve();
70+
if (fromVersion < 3 && toVersion >= 3) {
71+
// Brand new clients don't need to drop and recreate--only clients that
72+
// potentially have corrupt data.
73+
if (fromVersion !== 0) {
74+
dropQueryCache(db);
75+
createQueryCache(db);
76+
}
77+
p = p.next(() => writeEmptyTargetGlobalEntry(txn));
8078
}
8179

82-
if (fromVersion > 0 && fromVersion < 3 && toVersion >= 3) {
80+
if (fromVersion > 0 && fromVersion < 4 && toVersion >= 4) {
8381
// Schema version 3 uses auto-generated keys to generate globally unique
8482
// mutation batch IDs (this was previously ensured internally by the
8583
// client). To migrate to the new schema, we have to read all mutations
@@ -89,25 +87,11 @@ export function createOrUpgradeDb(
8987
p = p.next(() => upgradeMutationBatchSchemaAndMigrateData(db, txn));
9088
}
9189

92-
if (fromVersion < 3 && toVersion >= 3) {
90+
if (fromVersion < 4 && toVersion >= 4) {
9391
p = p.next(() => {
9492
createClientMetadataStore(db);
9593
createRemoteDocumentChangesStore(db);
9694
});
97-
=======
98-
// Migration 2 to populate the targetGlobal object no longer needed since
99-
// migration 3 unconditionally clears it.
100-
101-
let p = PersistencePromise.resolve();
102-
if (fromVersion < 3 && toVersion >= 3) {
103-
// Brand new clients don't need to drop and recreate--only clients that
104-
// potentially have corrupt data.
105-
if (fromVersion !== 0) {
106-
dropQueryCache(db);
107-
createQueryCache(db);
108-
}
109-
p = p.next(() => writeEmptyTargetGlobalEntry(txn));
110-
>>>>>>> master
11195
}
11296

11397
return p;
@@ -711,12 +695,14 @@ export const V1_STORES = [
711695
DbTargetDocument.store
712696
];
713697

698+
// V2 is no longer usable (see comment at top of file)
699+
714700
// Visible for testing
715-
export const V2_STORES = V1_STORES;
701+
export const V3_STORES = V1_STORES;
716702

717703
// Visible for testing
718-
export const V3_STORES = [
719-
...V2_STORES,
704+
export const V4_STORES = [
705+
...V3_STORES,
720706
DbClientMetadata.store,
721707
DbRemoteDocumentChanges.store
722708
];
@@ -726,4 +712,4 @@ export const V3_STORES = [
726712
* used when creating transactions so that access across all stores is done
727713
* atomically.
728714
*/
729-
export const ALL_STORES = V3_STORES;
715+
export const ALL_STORES = V4_STORES;

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

+26-50
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ import {
2222
createOrUpgradeDb,
2323
DbMutationBatch,
2424
DbMutationBatchKey,
25-
<<<<<<< HEAD
2625
DbOwner,
2726
DbOwnerKey,
2827
DbTarget,
2928
DbTargetGlobal,
3029
DbTargetGlobalKey,
3130
SCHEMA_VERSION,
3231
V1_STORES,
33-
V2_STORES,
34-
V3_STORES
32+
V3_STORES,
33+
DbTargetKey,
34+
DbTimestamp,
35+
V4_STORES
3536
} from '../../../src/local/indexeddb_schema';
3637
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db';
3738
import { PersistencePromise } from '../../../src/local/persistence_promise';
@@ -41,16 +42,7 @@ import { JsonProtoSerializer } from '../../../src/remote/serializer';
4142
import { PlatformSupport } from '../../../src/platform/platform';
4243
import { AsyncQueue } from '../../../src/util/async_queue';
4344
import { SharedFakeWebStorage, TestPlatform } from '../../util/test_platform';
44-
=======
45-
DbTarget,
46-
DbTargetGlobal,
47-
DbTargetGlobalKey,
48-
DbTargetKey,
49-
DbTimestamp
50-
} from '../../../src/local/indexeddb_schema';
51-
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db';
5245
import { SnapshotVersion } from '../../../src/core/snapshot_version';
53-
>>>>>>> master
5446

5547
const INDEXEDDB_TEST_DATABASE_PREFIX = 'schemaTest/';
5648
const INDEXEDDB_TEST_DATABASE =
@@ -126,6 +118,17 @@ function getAllObjectStores(db: IDBDatabase): string[] {
126118
return objectStores;
127119
}
128120

121+
function getTargetCount(db: IDBDatabase): Promise<number> {
122+
const sdb = new SimpleDb(db);
123+
return sdb
124+
.runTransaction('readonly', [DbTargetGlobal.store], txn =>
125+
txn
126+
.store<DbTargetGlobalKey, DbTargetGlobal>(DbTargetGlobal.store)
127+
.get(DbTargetGlobal.key)
128+
)
129+
.then(metadata => metadata.targetCount);
130+
}
131+
129132
describe('IndexedDbSchema: createOrUpgradeDb', () => {
130133
if (!IndexedDbPersistence.isAvailable()) {
131134
console.warn('No IndexedDB. Skipping createOrUpgradeDb() tests.');
@@ -144,31 +147,19 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
144147
});
145148
});
146149

147-
<<<<<<< HEAD
148-
it('can install schema version 2', () => {
149-
return withDb(2, db => {
150-
expect(db.version).to.equal(2);
150+
it('can install schema version 3', () => {
151+
return withDb(3, db => {
152+
expect(db.version).to.equal(3);
151153
// We should have all of the stores, we should have the target global row
152154
// and we should not have any targets counted, because there are none.
153-
expect(getAllObjectStores(db)).to.have.members(V2_STORES);
155+
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
154156
// Check the target count. We haven't added any targets, so we expect 0.
155157
return getTargetCount(db).then(targetCount => {
156158
expect(targetCount).to.equal(0);
157159
});
158160
});
159161
});
160162

161-
it('can install schema version 3', () => {
162-
return withDb(3, async db => {
163-
expect(db.version).to.be.equal(3);
164-
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
165-
});
166-
});
167-
168-
it('can upgrade from schema version 1 to 2', () => {
169-
const expectedTargetCount = 5;
170-
return withDb(1, db => {
171-
=======
172163
it('drops the query cache from 2 to 3', () => {
173164
const userId = 'user';
174165
const batchId = 1;
@@ -189,7 +180,6 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
189180
);
190181

191182
return withDb(2, db => {
192-
>>>>>>> master
193183
const sdb = new SimpleDb(db);
194184
return sdb.runTransaction(
195185
'readwrite',
@@ -213,24 +203,11 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
213203
.next(() => mutations.put(expectedMutation))
214204
);
215205
}
216-
<<<<<<< HEAD
217-
return p;
218-
});
219-
}).then(() =>
220-
withDb(2, db => {
221-
expect(db.version).to.equal(2);
222-
expect(getAllObjectStores(db)).to.have.members(V2_STORES);
223-
return getTargetCount(db).then(targetCount => {
224-
expect(targetCount).to.equal(expectedTargetCount);
225-
});
226-
})
227-
);
228-
=======
229206
);
230207
}).then(() => {
231208
return withDb(3, db => {
232209
expect(db.version).to.equal(3);
233-
expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
210+
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
234211

235212
const sdb = new SimpleDb(db);
236213
return sdb.runTransaction(
@@ -259,7 +236,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
259236
const expected = JSON.parse(JSON.stringify(resetTargetGlobal));
260237
expect(targetGlobalEntry).to.deep.equal(expected);
261238
})
262-
.next(() => mutations.get([userId, batchId]))
239+
.next(() => mutations.get(batchId))
263240
.next(mutation => {
264241
// Mutations should be unaffected.
265242
expect(mutation.userId).to.equal(userId);
@@ -269,10 +246,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
269246
);
270247
});
271248
});
272-
>>>>>>> master
273249
});
274250

275-
it('can upgrade from schema version 2 to 3', () => {
251+
it('can upgrade from schema version 3 to 4', () => {
276252
const testWrite = { delete: 'foo' };
277253
const testMutations = [
278254
{
@@ -295,7 +271,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
295271
}
296272
];
297273

298-
return withDb(2, db => {
274+
return withDb(3, db => {
299275
const sdb = new SimpleDb(db);
300276
return sdb.runTransaction('readwrite', [DbMutationBatch.store], txn => {
301277
const store = txn.store(DbMutationBatch.store);
@@ -306,9 +282,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
306282
return p;
307283
});
308284
}).then(() =>
309-
withDb(3, db => {
310-
expect(db.version).to.be.equal(3);
311-
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
285+
withDb(4, db => {
286+
expect(db.version).to.be.equal(4);
287+
expect(getAllObjectStores(db)).to.have.members(V4_STORES);
312288

313289
const sdb = new SimpleDb(db);
314290
return sdb.runTransaction('readwrite', [DbMutationBatch.store], txn => {

0 commit comments

Comments
 (0)