Skip to content

Commit 3c0b3ee

Browse files
Simplify
1 parent 77a52fb commit 3c0b3ee

File tree

6 files changed

+16
-23
lines changed

6 files changed

+16
-23
lines changed

packages/firestore/src/local/indexeddb_mutation_batch_impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export function removeMutationBatch(
7979
/**
8080
* Returns an approximate size for the given document.
8181
*/
82-
export function dbDocumentSize(doc: DbRemoteDocument): number {
82+
export function dbDocumentSize(doc: DbRemoteDocument | null): number {
83+
if (!doc) return 0;
84+
8385
let value: unknown;
8486
if (doc.document) {
8587
value = doc.document;

packages/firestore/src/local/indexeddb_remote_document_cache.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class IndexedDbRemoteDocumentCacheImpl implements IndexedDbRemoteDocumentCache {
148148
const doc = this.maybeDecodeDocument(documentKey, dbRemoteDoc);
149149
return {
150150
document: doc,
151-
size: dbRemoteDoc ? dbDocumentSize(dbRemoteDoc) : 0
151+
size: dbDocumentSize(dbRemoteDoc)
152152
};
153153
});
154154
}
@@ -187,16 +187,8 @@ class IndexedDbRemoteDocumentCacheImpl implements IndexedDbRemoteDocumentCache {
187187
documentKeys,
188188
(key, dbRemoteDoc) => {
189189
const doc = this.maybeDecodeDocument(key, dbRemoteDoc);
190-
if (doc.isValidDocument()) {
191-
results = results.insert(key, doc);
192-
sizeMap = sizeMap.insert(key, dbDocumentSize(dbRemoteDoc!));
193-
} else {
194-
results = results.insert(
195-
key,
196-
MutableDocument.newInvalidDocument(key)
197-
);
198-
sizeMap = sizeMap.insert(key, 0);
199-
}
190+
results = results.insert(key, doc);
191+
sizeMap = sizeMap.insert(key, dbDocumentSize(dbRemoteDoc));
200192
}
201193
).next(() => {
202194
return { documents: results, sizeMap };

packages/firestore/src/model/mutation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export function preconditionIsValidForDocument(
188188
* PatchMutation InvalidDocument(v0) UnknownDocument(v3)
189189
* DeleteMutation Document(v3) NoDocument(v0)
190190
* DeleteMutation NoDocument(v3) NoDocument(v0)
191-
* DeleteMutation InvalidDocument(v0) NoDocument(v0)
191+
* DeleteMutation InvalidDocument(v0) NoDocument(v0)
192192
*
193193
* For acknowledged mutations, we use the updateTime of the WriteResponse as
194194
* the resulting version for Set and Patch mutations. As deletes have no

packages/firestore/src/model/object_value.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import {
19-
MapValue,
2019
MapValue as ProtoMapValue,
2120
Value as ProtoValue
2221
} from '../protos/firestore_proto_api';
@@ -82,8 +81,8 @@ export class ObjectValue {
8281
}
8382

8483
/** Returns the full protobuf representation. */
85-
toProto(): { mapValue: MapValue } {
86-
return this.field(FieldPath.emptyPath()) as { mapValue: MapValue };
84+
toProto(): { mapValue: ProtoMapValue } {
85+
return this.field(FieldPath.emptyPath()) as { mapValue: ProtoMapValue };
8786
}
8887

8988
/**

packages/firestore/src/remote/serializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export function fromDocument(
410410
if (hasCommittedMutations) {
411411
result.setHasCommittedMutations();
412412
}
413-
return result;
413+
return hasCommittedMutations ? result.setHasCommittedMutations() : result;
414414
}
415415

416416
function fromFound(

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,29 +424,29 @@ function genericRemoteDocumentCacheTests(
424424
// This test verifies that the MemoryMutationCache returns copies of all
425425
// data to ensure that the documents in the cache cannot be modified.
426426
function verifyOldValue(d: Document): void {
427-
expect(d.data.field(field('ver'))).to.deep.equal(wrap(0));
427+
expect(d.data.field(field('state'))).to.deep.equal(wrap('old'));
428428
}
429429

430-
let document = doc('coll/doc', 1, { ver: 0 });
430+
let document = doc('coll/doc', 1, { state: 'old' });
431431
await cache.addEntries([document], /* readTime= */ version(1));
432432
verifyOldValue(document);
433-
document.data.set(field('ver'), wrap(1));
433+
document.data.set(field('state'), wrap('new'));
434434

435435
document = await cache.getEntry(key('coll/doc'));
436436
verifyOldValue(document);
437-
document.data.set(field('ver'), wrap(1));
437+
document.data.set(field('state'), wrap('new'));
438438

439439
document = await cache
440440
.getEntries(documentKeySet(key('coll/doc')))
441441
.then(m => m.get(key('coll/doc'))!);
442442
verifyOldValue(document);
443-
document.data.set(field('ver'), wrap(1));
443+
document.data.set(field('state'), wrap('new'));
444444

445445
document = await cache
446446
.getEntries(documentKeySet(key('coll/doc')))
447447
.then(m => m.get(key('coll/doc'))!);
448448
verifyOldValue(document);
449-
document.data.set(field('ver'), wrap(1));
449+
document.data.set(field('state'), wrap('new'));
450450

451451
const query1 = query('coll');
452452
document = await cache

0 commit comments

Comments
 (0)