Skip to content

Commit 65cdcac

Browse files
Review
1 parent dead3b5 commit 65cdcac

File tree

9 files changed

+33
-31
lines changed

9 files changed

+33
-31
lines changed

packages/firestore/src/api/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import {
9696
import { UserDataWriter } from './user_data_writer';
9797
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
9898
import { Provider } from '@firebase/component';
99-
import {Dict} from "../util/obj";
99+
import { Dict } from '../util/obj';
100100

101101
// settings() defaults:
102102
const DEFAULT_HOST = 'firestore.googleapis.com';

packages/firestore/src/core/sync_engine.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
413413
const changes = await this.localStore.applyRemoteEvent(remoteEvent);
414414
// Update `receivedDocument` as appropriate for any limbo targets.
415415
remoteEvent.targetChanges.forEach((targetChange, targetId) => {
416-
const limboResolution = this.activeLimboResolutionsByTarget.get(targetId);
416+
const limboResolution = this.activeLimboResolutionsByTarget.get(
417+
targetId
418+
);
417419
if (limboResolution) {
418420
// Since this is a limbo resolution lookup, it's for a single document
419421
// and it could be added, modified, or removed, but not a combination.
@@ -491,7 +493,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
491493

492494
// PORTING NOTE: Multi-tab only.
493495
this.sharedClientState.updateQueryState(targetId, 'rejected', err);
494-
496+
495497
const limboResolution = this.activeLimboResolutionsByTarget.get(targetId);
496498
const limboKey = limboResolution && limboResolution.key;
497499
if (limboKey) {
@@ -755,7 +757,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
755757

756758
this.remoteStore.unlisten(limboTargetId);
757759
this.activeLimboTargetsByKey = this.activeLimboTargetsByKey.remove(key);
758-
this.activeLimboResolutionsByTarget.delete(limboTargetId);
760+
this.activeLimboResolutionsByTarget.delete(limboTargetId);
759761
this.pumpEnqueuedLimboResolutions();
760762
}
761763

@@ -807,9 +809,10 @@ this.activeLimboResolutionsByTarget.delete(limboTargetId);
807809
) {
808810
const key = this.enqueuedLimboResolutions.shift()!;
809811
const limboTargetId = this.limboTargetIdGenerator.next();
810-
this.activeLimboResolutionsByTarget.set(limboTargetId, new LimboResolution(
811-
key
812-
));
812+
this.activeLimboResolutionsByTarget.set(
813+
limboTargetId,
814+
new LimboResolution(key)
815+
);
813816
this.activeLimboTargetsByKey = this.activeLimboTargetsByKey.insert(
814817
key,
815818
limboTargetId

packages/firestore/src/model/values.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as api from '../protos/firestore_proto_api';
1919

2020
import { TypeOrder } from './field_value';
2121
import { assert, fail } from '../util/assert';
22-
import { forEach, size } from '../util/obj';
22+
import { forEach, objectSize } from '../util/obj';
2323
import { ByteString } from '../util/byte_string';
2424
import { isNegativeZero } from '../util/types';
2525
import { DocumentKey } from './document_key';
@@ -162,7 +162,7 @@ function objectEquals(left: api.Value, right: api.Value): boolean {
162162
const leftMap = left.mapValue!.fields || {};
163163
const rightMap = right.mapValue!.fields || {};
164164

165-
if (size(leftMap) !== size(rightMap)) {
165+
if (objectSize(leftMap) !== objectSize(rightMap)) {
166166
return false;
167167
}
168168

packages/firestore/src/remote/watch_change.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,12 @@ export class WatchChangeAggregator {
595595
}
596596

597597
private ensureTargetState(targetId: TargetId): TargetState {
598-
if (!this.targetStates.has(targetId)) {
599-
this.targetStates.set(targetId, new TargetState());
598+
let result = this.targetStates.get(targetId);
599+
if (!result) {
600+
result = new TargetState();
601+
this.targetStates.set(targetId, result);
600602
}
601-
602-
return this.targetStates.get(targetId)!;
603+
return result;
603604
}
604605

605606
private ensureDocumentTargetMapping(key: DocumentKey): SortedSet<TargetId> {

packages/firestore/src/util/obj.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface Dict<V> {
2121
[stringKey: string]: V;
2222
}
2323

24-
export function size<V>(obj: object): number {
24+
export function objectSize<V>(obj: object): number {
2525
let count = 0;
2626
for (const key in obj) {
2727
if (Object.prototype.hasOwnProperty.call(obj, key)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { PlatformSupport } from '../../../src/platform/platform';
4141
import { AsyncQueue } from '../../../src/util/async_queue';
4242
import { FirestoreError } from '../../../src/util/error';
4343
import { AutoId } from '../../../src/util/misc';
44-
import { size } from '../../../src/util/obj';
44+
import { objectSize } from '../../../src/util/obj';
4545
import { SortedSet } from '../../../src/util/sorted_set';
4646
import {
4747
clearWebStorage,
@@ -103,7 +103,7 @@ class TestSharedClientSyncer implements SharedClientStateSyncer {
103103

104104
get sharedClientState(): TestSharedClientState {
105105
return {
106-
mutationCount: size(this.mutationState),
106+
mutationCount: objectSize(this.mutationState),
107107
mutationState: this.mutationState,
108108
targetIds: this.activeTargets,
109109
targetState: this.queryState,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ export interface LimboMap {
6363
[key: string]: TargetId;
6464
}
6565

66+
export interface ActiveTargetSpec {
67+
queries: SpecQuery[];
68+
resumeToken: string;
69+
}
70+
6671
export interface ActiveTargetMap {
67-
[targetId: string]: { queries: SpecQuery[]; resumeToken: string };
72+
[targetId: string]: ActiveTargetSpec;
6873
}
6974

7075
/**

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import { assert, fail } from '../../../src/util/assert';
8686
import { AsyncQueue, TimerId } from '../../../src/util/async_queue';
8787
import { FirestoreError } from '../../../src/util/error';
8888
import { primitiveComparator } from '../../../src/util/misc';
89-
import { forEach, size } from '../../../src/util/obj';
89+
import { forEach, objectSize } from '../../../src/util/obj';
9090
import { ObjectMap } from '../../../src/util/obj_map';
9191
import { Deferred, sequence } from '../../../src/util/promise';
9292
import {
@@ -116,6 +116,7 @@ import {
116116
import { MULTI_CLIENT_TAG } from './describe_spec';
117117
import { ByteString } from '../../../src/util/byte_string';
118118
import { SortedSet } from '../../../src/util/sorted_set';
119+
import { ActiveTargetMap, ActiveTargetSpec } from './spec_builder';
119120

120121
const ARBITRARY_SEQUENCE_NUMBER = 2;
121122

@@ -412,10 +413,7 @@ abstract class TestRunner {
412413

413414
private expectedActiveLimboDocs: DocumentKey[];
414415
private expectedEnqueuedLimboDocs: DocumentKey[];
415-
private expectedActiveTargets: Map<
416-
TargetId,
417-
{ queries: SpecQuery[]; resumeToken: string }
418-
>;
416+
private expectedActiveTargets: Map<TargetId, ActiveTargetSpec>;
419417

420418
private networkEnabled = true;
421419

@@ -465,10 +463,7 @@ abstract class TestRunner {
465463
this.maxConcurrentLimboResolutions = config.maxConcurrentLimboResolutions;
466464
this.expectedActiveLimboDocs = [];
467465
this.expectedEnqueuedLimboDocs = [];
468-
this.expectedActiveTargets =new Map<
469-
TargetId,
470-
{ queries: SpecQuery[]; resumeToken: string }
471-
>();
466+
this.expectedActiveTargets = new Map<TargetId, ActiveTargetSpec>();
472467
this.acknowledgedDocs = [];
473468
this.rejectedDocs = [];
474469
this.snapshotsInSyncListeners = [];
@@ -1215,7 +1210,7 @@ abstract class TestRunner {
12151210
);
12161211
delete actualTargets[targetId];
12171212
});
1218-
expect(size(actualTargets)).to.equal(
1213+
expect(objectSize(actualTargets)).to.equal(
12191214
0,
12201215
'Unexpected active targets: ' + JSON.stringify(actualTargets)
12211216
);
@@ -1713,9 +1708,7 @@ export interface StateExpectation {
17131708
/**
17141709
* Current expected active targets. Verified in each step until overwritten.
17151710
*/
1716-
activeTargets?: {
1717-
[targetId: number]: { queries: SpecQuery[]; resumeToken: string };
1718-
};
1711+
activeTargets?: ActiveTargetMap;
17191712
/**
17201713
* Expected set of callbacks for previously written docs.
17211714
*/

packages/firestore/test/util/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export function byteStringFromString(value: string): ByteString {
512512
return ByteString.fromBase64String(base64);
513513
}
514514

515-
/**
515+
/**
516516
* Decodes a base 64 decoded string.
517517
*
518518
* Note that this is typed to accept Uint8Arrays to match the types used

0 commit comments

Comments
 (0)