Skip to content

Commit bb8fdaf

Browse files
Cleanup
1 parent ff719f2 commit bb8fdaf

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

packages/firestore/src/local/indexeddb_index_manager.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ export class IndexedDbIndexManager implements IndexManager {
640640
transaction: PersistenceTransaction,
641641
documents: DocumentMap
642642
): PersistencePromise<void> {
643+
// Porting Note: `getFieldIndexes()` on Web does not cache index lookups as
644+
// it could be used across different IndexedDB transactions. As any cached
645+
// data might invalidated by other multi-tab clients, we can only trust data
646+
// within a single IndexedDB transaction. We therefore add a cache here.
643647
const memoizedIndexes = new Map<string, FieldIndex[]>();
644648
return PersistencePromise.forEach(documents, (key, doc) => {
645649
const memoizedCollectionIndexes = memoizedIndexes.get(
@@ -834,7 +838,7 @@ export class IndexedDbIndexManager implements IndexManager {
834838

835839
/**
836840
* Applies notIn and != filters by taking the provided ranges and excluding
837-
* any values that match `notInValue` from these ranges. As an example,
841+
* any values that match the `notInValue` from these ranges. As an example,
838842
* '[foo > 2 && foo != 3]` becomes `[foo > 2 && < 3, foo > 3]`.
839843
*/
840844
private applyNotIn(
@@ -846,17 +850,17 @@ export class IndexedDbIndexManager implements IndexManager {
846850
}
847851

848852
// The values need to be sorted so that we can return a sorted set of
849-
// non-overlapping ragnes.
853+
// non-overlapping ranges.
850854
notInValues.sort((l, r) => compareByteArrays(l, r));
851855

852856
const notInRanges: IDBKeyRange[] = [];
853857
for (const indexRange of indexRanges) {
854858
// Use the existing bounds and interleave the notIn values. This means
855-
// that we would split an existing range into two ranges that exclude
859+
// that we would split an existing range into multiple ranges that exclude
856860
// the values from any notIn filter.
857861

858862
// The first index range starts with the lower bound and ends at the
859-
// first not in value (exclusive).
863+
// first notIn value (exclusive).
860864
notInRanges.push(
861865
IDBKeyRange.bound(
862866
indexRange.lower,
@@ -867,7 +871,7 @@ export class IndexedDbIndexManager implements IndexManager {
867871
);
868872

869873
for (let i = 1; i < notInValues.length - 1; ++i) {
870-
// Each index range that we need to scan starts at the last not in value
874+
// Each index range that we need to scan starts at the last notIn value
871875
// and ends at the next.
872876
notInRanges.push(
873877
IDBKeyRange.bound(
@@ -901,18 +905,18 @@ export class IndexedDbIndexManager implements IndexManager {
901905

902906
/**
903907
* Generates the index entry that can be used to create the cutoff for `value`
904-
* on the provided index range..
908+
* on the provided index range.
905909
*/
906910
private generateNotInBound(
907-
existingRange: IDBKeyRange,
911+
existingRange: DbIndexEntryKey,
908912
value: Uint8Array
909913
): DbIndexEntryKey {
910914
return [
911-
/* indexId= */ existingRange.lower[0],
912-
/* userId= */ existingRange.lower[1],
913-
/* arrayValue= */ existingRange.lower[2],
915+
/* indexId= */ existingRange[0],
916+
/* userId= */ existingRange[1],
917+
/* arrayValue= */ existingRange[2],
914918
value,
915-
''
919+
/* documentKey= */ ''
916920
];
917921
}
918922
}

packages/firestore/src/local/simple_db.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,9 @@ export class SimpleDbStore<
660660
range?: IDBKeyRange
661661
): PersistencePromise<ValueType[]> {
662662
const iterateOptions = this.options(indexOrRange, range);
663-
if (!iterateOptions.index) {
664-
// Use `getAll()` if we are not using a custom index.
663+
// Use `getAll()` if the browser supports IndexedDB v3, as it is roughly
664+
// 20% faster. Unfortunately, getAll() does not support custom indices.
665+
if (!iterateOptions.index && typeof this.store.getAll === 'function') {
665666
const request = this.store.getAll(iterateOptions.range);
666667
return new PersistencePromise((resolve, reject) => {
667668
request.onerror = (event: Event) => {

packages/firestore/test/unit/api/bytes.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ describe('Bytes', () => {
4747
});
4848
});
4949

50-
it('throws on invalid Base64 strings', () => {
51-
expect(() => Bytes.fromBase64String('not-base64!')).to.throw(
52-
/Failed to construct data from Base64 string:/
53-
);
54-
});
5550

5651
it('works with instanceof checks', () => {
5752
expect(Bytes.fromBase64String('') instanceof Bytes).to.equal(true);

0 commit comments

Comments
 (0)