Skip to content

Commit a125161

Browse files
Remove unused code
1 parent f1ddd70 commit a125161

15 files changed

+16
-159
lines changed

packages/firestore/src/core/snapshot_version.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ import { Timestamp } from '../api/timestamp';
2424
export class SnapshotVersion {
2525
static readonly MIN = new SnapshotVersion(new Timestamp(0, 0));
2626

27-
// TODO(b/34176344): Once we no longer need to use the old alpha protos,
28-
// delete this constructor and use a timestamp-backed version everywhere.
29-
static fromMicroseconds(value: number): SnapshotVersion {
30-
const seconds = Math.floor(value / 1e6);
31-
const nanos = (value % 1e6) * 1e3;
32-
return new SnapshotVersion(new Timestamp(seconds, nanos));
33-
}
34-
3527
static fromTimestamp(value: Timestamp): SnapshotVersion {
3628
return new SnapshotVersion(value);
3729
}

packages/firestore/src/local/encoded_resource_path.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,3 @@ export function decode(path: EncodedResourcePath): ResourcePath {
175175

176176
return new ResourcePath(segments);
177177
}
178-
179-
/**
180-
* Computes the prefix successor of the given path, computed by encode above.
181-
* A prefix successor is the first key that cannot be prefixed by the given
182-
* path. It's useful for defining the end of a prefix scan such that all keys
183-
* in the scan have the same prefix.
184-
*
185-
* Note that this is not a general prefix successor implementation, which is
186-
* tricky to get right with Strings, given that they encode down to UTF-8.
187-
* Instead this relies on the fact that all paths encoded by this class are
188-
* always terminated with a separator, and so a successor can always be
189-
* cheaply computed by incrementing the last character of the path.
190-
*/
191-
export function prefixSuccessor(
192-
path: EncodedResourcePath
193-
): EncodedResourcePath {
194-
const c = path.charCodeAt(path.length - 1);
195-
// TODO(mcg): this really should be a general thing, but not worth it right
196-
// now
197-
assert(c === 1, 'successor may only operate on paths generated by encode');
198-
return path.substring(0, path.length - 1) + String.fromCharCode(c + 1);
199-
}

packages/firestore/src/local/local_serializer.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ import * as api from '../protos/firestore_proto_api';
2929
import { JsonProtoSerializer } from '../remote/serializer';
3030
import { assert, fail } from '../util/assert';
3131
import { ByteString } from '../util/byte_string';
32-
33-
import { documentKeySet, DocumentKeySet } from '../model/collections';
3432
import { Target } from '../core/target';
35-
import { decode, encode, EncodedResourcePath } from './encoded_resource_path';
3633
import {
3734
DbMutationBatch,
3835
DbNoDocument,
@@ -174,30 +171,6 @@ export class LocalSerializer {
174171
);
175172
}
176173

177-
/*
178-
* Encodes a set of document keys into an array of EncodedResourcePaths.
179-
*/
180-
toDbResourcePaths(keys: DocumentKeySet): EncodedResourcePath[] {
181-
const encodedKeys: EncodedResourcePath[] = [];
182-
183-
keys.forEach(key => {
184-
encodedKeys.push(encode(key.path));
185-
});
186-
187-
return encodedKeys;
188-
}
189-
190-
/** Decodes an array of EncodedResourcePaths into a set of document keys. */
191-
fromDbResourcePaths(encodedPaths: EncodedResourcePath[]): DocumentKeySet {
192-
let keys = documentKeySet();
193-
194-
for (const documentKey of encodedPaths) {
195-
keys = keys.add(new DocumentKey(decode(documentKey)));
196-
}
197-
198-
return keys;
199-
}
200-
201174
/** Decodes a DbTarget into TargetData */
202175
fromDbTarget(dbTarget: DbTarget): TargetData {
203176
const version = this.fromDbTimestamp(dbTarget.readTime);

packages/firestore/src/local/reference_set.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ export class ReferenceSet {
4343
// A set of outstanding references to a document sorted by target id.
4444
private refsByTarget = new SortedSet(DocReference.compareByTargetId);
4545

46-
/** Returns true if the reference set contains no references. */
47-
isEmpty(): boolean {
48-
return this.refsByKey.isEmpty();
49-
}
50-
5146
/** Adds a reference to the given document key for the given ID. */
5247
addReference(key: DocumentKey, id: TargetId | BatchId): void {
5348
const ref = new DocReference(key, id);

packages/firestore/src/local/target_data.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,4 @@ export class TargetData {
118118
this.resumeToken
119119
);
120120
}
121-
122-
isEqual(other: TargetData): boolean {
123-
return (
124-
this.targetId === other.targetId &&
125-
this.purpose === other.purpose &&
126-
this.sequenceNumber === other.sequenceNumber &&
127-
this.snapshotVersion.isEqual(other.snapshotVersion) &&
128-
this.lastLimboFreeSnapshotVersion.isEqual(
129-
other.lastLimboFreeSnapshotVersion
130-
) &&
131-
this.resumeToken.isEqual(other.resumeToken) &&
132-
this.target.isEqual(other.target)
133-
);
134-
}
135121
}

packages/firestore/src/remote/existence_filter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,4 @@
1818
export class ExistenceFilter {
1919
// TODO(b/33078163): just use simplest form of existence filter for now
2020
constructor(public count: number) {}
21-
22-
isEqual(other: ExistenceFilter): boolean {
23-
return other && other.count === this.count;
24-
}
2521
}

packages/firestore/src/util/async_queue.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,6 @@ export class AsyncQueue {
289289
const message = error.stack || error.message || '';
290290
logError('INTERNAL UNHANDLED ERROR: ', message);
291291

292-
// Escape the promise chain and throw the error globally so that
293-
// e.g. any global crash reporting library detects and reports it.
294-
// (but not for simulated errors in our tests since this breaks mocha)
295-
if (message.indexOf('Firestore Test Simulated Error') < 0) {
296-
setTimeout(() => {
297-
throw error;
298-
}, 0);
299-
}
300-
301292
// Re-throw the error so that this.tail becomes a rejected Promise and
302293
// all further attempts to chain (via .then) will just short-circuit
303294
// and return the rejected Promise.

packages/firestore/src/util/sorted_set.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@ export class SortedSet<T> {
3131
this.data = new SortedMap<T, boolean>(this.comparator);
3232
}
3333

34-
/**
35-
* Creates a SortedSet from the keys of the map.
36-
* This is currently implemented as an O(n) copy.
37-
*/
38-
static fromMapKeys<K, V>(map: SortedMap<K, V>): SortedSet<K> {
39-
let keys = new SortedSet<K>(map.comparator);
40-
map.forEach(key => {
41-
keys = keys.add(key);
42-
});
43-
return keys;
44-
}
45-
4634
has(elem: T): boolean {
4735
return this.data.get(elem) !== null;
4836
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,8 @@ describe('EncodedResourcePath', () => {
124124
path('food')
125125
]);
126126
});
127-
128-
it('prefixes successors correctly', async () => {
129-
assertPrefixSuccessorEquals('\u0001\u0002', ResourcePath.EMPTY_PATH);
130-
assertPrefixSuccessorEquals(
131-
'foo' + sep + 'bar\u0001\u0002',
132-
path('foo/bar')
133-
);
134-
});
135127
});
136128

137-
function assertPrefixSuccessorEquals(
138-
expected: string,
139-
path: ResourcePath
140-
): void {
141-
expect(
142-
EncodedResourcePath.prefixSuccessor(EncodedResourcePath.encode(path))
143-
).to.deep.equal(expected);
144-
}
145-
146129
function assertEncoded(expected: string, path: ResourcePath): Promise<void> {
147130
const encoded = EncodedResourcePath.encode(path);
148131
expect(encoded).to.deep.equal(expected);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Timestamp } from '../../../src/api/timestamp';
2020
import { User } from '../../../src/auth/user';
2121
import { ListenSequence } from '../../../src/core/listen_sequence';
2222
import { Query } from '../../../src/core/query';
23-
import { SnapshotVersion } from '../../../src/core/snapshot_version';
2423
import { ListenSequenceNumber, TargetId } from '../../../src/core/types';
2524
import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
2625
import {
@@ -49,7 +48,7 @@ import {
4948
SetMutation
5049
} from '../../../src/model/mutation';
5150
import { AsyncQueue } from '../../../src/util/async_queue';
52-
import { key, path, wrapObject } from '../../util/helpers';
51+
import { key, path, version, wrapObject } from '../../util/helpers';
5352
import { SortedMap } from '../../../src/util/sorted_map';
5453
import * as PersistenceTestHelpers from './persistence_test_helpers';
5554
import { primitiveComparator } from '../../../src/util/misc';
@@ -246,7 +245,7 @@ function genericLruGarbageCollectorTests(
246245
const key = nextTestDocumentKey();
247246
return new Document(
248247
key,
249-
SnapshotVersion.fromMicroseconds(1000),
248+
version(1000),
250249
wrapObject({
251250
foo: 3,
252251
bar: false
@@ -784,7 +783,7 @@ function genericLruGarbageCollectorTests(
784783
txn => {
785784
const doc = new Document(
786785
middleDocToUpdate,
787-
SnapshotVersion.fromMicroseconds(2000),
786+
version(2000),
788787
wrapObject({
789788
foo: 4,
790789
bar: true

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ describe('ReferenceSet', () => {
2424
const documentKey = key('foo/bar');
2525

2626
const refSet = new ReferenceSet();
27-
expect(refSet.isEmpty()).to.be.true;
2827
expect(refSet.containsKey(documentKey)).to.be.false;
2928
refSet.addReference(documentKey, 1);
30-
expect(refSet.isEmpty()).to.be.false;
3129
expect(refSet.containsKey(documentKey)).to.be.true;
3230
refSet.addReference(documentKey, 2);
3331
expect(refSet.containsKey(documentKey)).to.be.true;
@@ -37,7 +35,6 @@ describe('ReferenceSet', () => {
3735
expect(refSet.containsKey(documentKey)).to.be.true;
3836
refSet.removeReference(documentKey, 2);
3937
expect(refSet.containsKey(documentKey)).to.be.false;
40-
expect(refSet.isEmpty()).to.be.true;
4138
});
4239

4340
it('can remove all references for a target ID', () => {
@@ -49,17 +46,14 @@ describe('ReferenceSet', () => {
4946
refSet.addReference(key1, 1);
5047
refSet.addReference(key2, 1);
5148
refSet.addReference(key3, 2);
52-
expect(refSet.isEmpty()).to.be.false;
5349
expect(refSet.containsKey(key1)).to.be.true;
5450
expect(refSet.containsKey(key2)).to.be.true;
5551
expect(refSet.containsKey(key3)).to.be.true;
5652
refSet.removeReferencesForId(1);
57-
expect(refSet.isEmpty()).to.be.false;
5853
expect(refSet.containsKey(key1)).to.be.false;
5954
expect(refSet.containsKey(key2)).to.be.false;
6055
expect(refSet.containsKey(key3)).to.be.true;
6156
refSet.removeReferencesForId(2);
62-
expect(refSet.isEmpty()).to.be.true;
6357
expect(refSet.containsKey(key1)).to.be.false;
6458
expect(refSet.containsKey(key2)).to.be.false;
6559
expect(refSet.containsKey(key3)).to.be.false;

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,8 @@ describe('IndexedDbTargetCache', () => {
9292
originalSequenceNumber
9393
);
9494
const actualTargetData = await targetCache2.getTargetData(target);
95-
96-
if (process.env.USE_MOCK_PERSISTENCE !== 'YES') {
97-
// TODO(b/140573486): This fails on Node with persistence since the
98-
// resume token is read back as a string.
99-
expect(targetData.isEqual(actualTargetData!)).to.be.true;
100-
}
101-
95+
expect(targetData).to.deep.equal(actualTargetData);
96+
10297
const actualSnapshotVersion = await targetCache2.getLastRemoteSnapshotVersion();
10398
expect(snapshotVersion.isEqual(actualSnapshotVersion)).to.be.true;
10499
await db2.shutdown();
@@ -127,12 +122,12 @@ function genericTargetCacheTests(
127122
function testTargetData(
128123
target: Target,
129124
targetId: TargetId,
130-
version?: number
125+
testVersion?: number
131126
): TargetData {
132-
if (version === undefined) {
133-
version = 0;
127+
if (testVersion === undefined) {
128+
testVersion = 0;
134129
}
135-
const snapshotVersion = SnapshotVersion.fromMicroseconds(version);
130+
const snapshotVersion = version(testVersion);
136131
const resumeToken = resumeTokenForSnapshot(snapshotVersion);
137132
return new TargetData(
138133
target,

packages/firestore/test/unit/remote/serializer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ describe('Serializer', () => {
14201420
document: {
14211421
name: s.toName(key('coll/1')),
14221422
fields: wrap({ foo: 'bar' }).mapValue!.fields,
1423-
updateTime: s.toVersion(SnapshotVersion.fromMicroseconds(5))
1423+
updateTime: s.toVersion(version(5))
14241424
},
14251425
targetIds: [1, 2]
14261426
}
@@ -1440,7 +1440,7 @@ describe('Serializer', () => {
14401440
document: {
14411441
name: s.toName(key('coll/1')),
14421442
fields: wrap({ foo: 'bar' }).mapValue!.fields,
1443-
updateTime: s.toVersion(SnapshotVersion.fromMicroseconds(5))
1443+
updateTime: s.toVersion(version(5))
14441444
},
14451445
targetIds: [2],
14461446
removedTargetIds: [1]
@@ -1459,7 +1459,7 @@ describe('Serializer', () => {
14591459
const actual = s.fromWatchChange({
14601460
documentDelete: {
14611461
document: s.toName(key('coll/1')),
1462-
readTime: s.toVersion(SnapshotVersion.fromMicroseconds(5)),
1462+
readTime: s.toVersion(version(5)),
14631463
removedTargetIds: [1, 2]
14641464
}
14651465
});

packages/firestore/test/unit/util/sorted_set.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import { expect } from 'chai';
1919
import { primitiveComparator } from '../../../src/util/misc';
20-
import { SortedMap } from '../../../src/util/sorted_map';
2120
import { SortedSet } from '../../../src/util/sorted_set';
2221

2322
import { expectSetToEqual } from '../../util/helpers';
@@ -161,21 +160,6 @@ describe('SortedSet', () => {
161160
expect(set.unionWith(set2)).to.deep.equal(expected);
162161
});
163162

164-
it('can build set from map keys.', () => {
165-
const empty = new SortedSet<number>(primitiveComparator);
166-
const map = new SortedMap<number, string>(primitiveComparator)
167-
.insert(0, 'zero')
168-
.insert(2, 'two')
169-
.insert(4, 'four');
170-
const set = SortedSet.fromMapKeys(map);
171-
expect(set).to.deep.equal(
172-
empty
173-
.add(0)
174-
.add(2)
175-
.add(4)
176-
);
177-
});
178-
179163
it('returns indexes of elements', () => {
180164
const set = new SortedSet<number>(primitiveComparator)
181165
.add(-1)

packages/firestore/test/util/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { query } from './api_helpers';
9191
import { ByteString } from '../../src/util/byte_string';
9292
import { PlatformSupport } from '../../src/platform/platform';
9393
import { JsonProtoSerializer } from '../../src/remote/serializer';
94+
import { Timestamp } from '../../src/api/timestamp';
9495

9596
export type TestSnapshotVersion = number;
9697

@@ -126,7 +127,9 @@ export function testUserDataReader(useProto3Json?: boolean): UserDataReader {
126127
}
127128

128129
export function version(v: TestSnapshotVersion): SnapshotVersion {
129-
return SnapshotVersion.fromMicroseconds(v);
130+
const seconds = Math.floor(v / 1e6);
131+
const nanos = (v % 1e6) * 1e3;
132+
return SnapshotVersion.fromTimestamp(new Timestamp(seconds, nanos));
130133
}
131134

132135
export function ref(

0 commit comments

Comments
 (0)