Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmidt-sebastian/a5d0265e6e28fdc5076a00363c77932c to your computer and use it in GitHub Desktop.
Save schmidt-sebastian/a5d0265e6e28fdc5076a00363c77932c to your computer and use it in GitHub Desktop.
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