Skip to content

Commit 77a52fb

Browse files
Simplify
1 parent ead9034 commit 77a52fb

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

packages/firestore/src/lite/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class Transaction {
9999
);
100100
} else {
101101
throw fail(
102-
`BatchGetDocumentsRequest returned unexpected document type: ${doc.constructor.name}`
102+
`BatchGetDocumentsRequest returned unexpected document: ${doc}`
103103
);
104104
}
105105
});

packages/firestore/src/local/indexeddb_remote_document_cache.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,15 @@ class IndexedDbRemoteDocumentCacheImpl implements IndexedDbRemoteDocumentCache {
141141
getSizedEntry(
142142
transaction: PersistenceTransaction,
143143
documentKey: DocumentKey
144-
): PersistencePromise<DocumentSizeEntry | null> {
144+
): PersistencePromise<DocumentSizeEntry> {
145145
return remoteDocumentsStore(transaction)
146146
.get(dbKey(documentKey))
147147
.next(dbRemoteDoc => {
148148
const doc = this.maybeDecodeDocument(documentKey, dbRemoteDoc);
149-
return doc.isValidDocument()
150-
? {
151-
document: doc,
152-
size: dbDocumentSize(dbRemoteDoc!)
153-
}
154-
: null;
149+
return {
150+
document: doc,
151+
size: dbRemoteDoc ? dbDocumentSize(dbRemoteDoc) : 0
152+
};
155153
});
156154
}
157155

@@ -546,13 +544,8 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
546544
return this.documentCache
547545
.getSizedEntry(transaction, documentKey)
548546
.next(getResult => {
549-
if (getResult === null) {
550-
this.documentSizes.set(documentKey, 0);
551-
return MutableDocument.newInvalidDocument(documentKey);
552-
} else {
553-
this.documentSizes.set(documentKey, getResult.size);
554-
return getResult.document;
555-
}
547+
this.documentSizes.set(documentKey, getResult.size);
548+
return getResult.document;
556549
});
557550
}
558551

packages/firestore/src/local/local_serializer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ export function fromDbRemoteDocument(
7979
const key = DocumentKey.fromSegments(remoteDoc.noDocument.path);
8080
const version = fromDbTimestamp(remoteDoc.noDocument.readTime);
8181
const document = MutableDocument.newNoDocument(key, version);
82-
if (remoteDoc.hasCommittedMutations) {
83-
document.setHasCommittedMutations();
84-
}
85-
return document;
82+
return remoteDoc.hasCommittedMutations
83+
? document.setHasCommittedMutations()
84+
: document;
8685
} else if (remoteDoc.unknownDocument) {
8786
const key = DocumentKey.fromSegments(remoteDoc.unknownDocument.path);
8887
const version = fromDbTimestamp(remoteDoc.unknownDocument.version);

packages/firestore/src/local/local_store_impl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,19 +1028,19 @@ function applyWriteToRemoteDocuments(
10281028
docKeys.forEach(docKey => {
10291029
promiseChain = promiseChain
10301030
.next(() => documentBuffer.getEntry(txn, docKey))
1031-
.next(remoteDoc => {
1031+
.next(doc => {
10321032
const ackVersion = batchResult.docVersions.get(docKey);
10331033
hardAssert(
10341034
ackVersion !== null,
10351035
'ackVersions should contain every doc in the write.'
10361036
);
1037-
if (remoteDoc.version.compareTo(ackVersion!) < 0) {
1038-
batch.applyToRemoteDocument(docKey, remoteDoc, batchResult);
1039-
if (remoteDoc.isValidDocument()) {
1037+
if (doc.version.compareTo(ackVersion!) < 0) {
1038+
batch.applyToRemoteDocument(docKey, doc, batchResult);
1039+
if (doc.isValidDocument()) {
10401040
// We use the commitVersion as the readTime rather than the
10411041
// document's updateTime since the updateTime is not advanced
10421042
// for updates that do not modify the underlying document.
1043-
documentBuffer.addEntry(remoteDoc, batchResult.commitVersion);
1043+
documentBuffer.addEntry(doc, batchResult.commitVersion);
10441044
}
10451045
}
10461046
});

0 commit comments

Comments
 (0)