Created
July 7, 2020 18:58
-
-
Save schmidt-sebastian/a5d0265e6e28fdc5076a00363c77932c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/packages/firestore/src/core/bundle.ts b/packages/firestore/src/core/bundle.ts | |
index b43853c8e..087f869d6 100644 | |
--- a/packages/firestore/src/core/bundle.ts | |
+++ b/packages/firestore/src/core/bundle.ts | |
@@ -67,7 +67,7 @@ export interface NamedQuery { | |
*/ | |
interface BundledDocument { | |
metadata: bundleProto.BundledDocumentMetadata; | |
- document: api.Document | undefined; | |
+ document?: api.Document; | |
} | |
/** | |
@@ -166,12 +166,7 @@ export class BundleLoader { | |
private queries: bundleProto.NamedQuery[] = []; | |
/** Batched documents to be saved into storage */ | |
private documents: BundledDocuments = []; | |
- /** | |
- * A BundleDocumentMetadata is added to the loader, it is saved here while | |
- * we wait for the actual document. | |
- */ | |
- private unpairedDocumentMetadata: bundleProto.BundledDocumentMetadata | null = null; | |
- | |
+ | |
constructor( | |
private metadata: bundleProto.BundleMetadata, | |
private localStore: LocalStore | |
@@ -192,41 +187,30 @@ export class BundleLoader { | |
debugAssert(!element.isBundleMetadata(), 'Unexpected bundle metadata.'); | |
this.progress.bytesLoaded += element.byteLength; | |
+ | |
+ let documentsLoaded = this.progress.documentsLoaded; | |
+ | |
if (element.payload.namedQuery) { | |
this.queries.push(element.payload.namedQuery); | |
- } | |
- | |
- if (element.payload.documentMetadata) { | |
- if (element.payload.documentMetadata.exists) { | |
- this.unpairedDocumentMetadata = element.payload.documentMetadata; | |
- } else { | |
- this.documents.push({ | |
- metadata: element.payload.documentMetadata, | |
- document: undefined | |
- }); | |
- this.progress.documentsLoaded += 1; | |
+ } else if (element.payload.documentMetadata) { | |
+ this.documents.push({metadata: element.payload.documentMetadata}); | |
+ if (!element.payload.documentMetadata.exists) { | |
+ ++documentsLoaded; | |
} | |
- } | |
- | |
- if (element.payload.document) { | |
- debugAssert( | |
- !!this.unpairedDocumentMetadata, | |
- 'Unexpected document when no pairing metadata is found' | |
+ } else if (element.payload.document) { | |
+ debugAssert(this.documents.length> 0 && this.documents[this.documents.length -1].metadata.name == element.payload.document.name, | |
+ '...' | |
); | |
- this.documents.push({ | |
- metadata: this.unpairedDocumentMetadata!, | |
- document: element.payload.document | |
- }); | |
- this.progress.documentsLoaded += 1; | |
- this.unpairedDocumentMetadata = null; | |
+ this.documents[this.documents.length - 1].document = element.payload.document; | |
+ ++documentsLoaded; | |
} | |
- // Loading a document metadata will not update progress. | |
- if (this.unpairedDocumentMetadata) { | |
- return null; | |
+ if (documentsLoaded !== this.progress.documentsLoaded) { | |
+ this.progress.documentsLoaded = documentsLoaded; | |
+ return this.progress; | |
} | |
- | |
- return { ...this.progress }; | |
+ | |
+ return null; | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment