diff --git a/packages/firestore/src/local/indexeddb_remote_document_cache.ts b/packages/firestore/src/local/indexeddb_remote_document_cache.ts index f6552a68765..d05ea4110ea 100644 --- a/packages/firestore/src/local/indexeddb_remote_document_cache.ts +++ b/packages/firestore/src/local/indexeddb_remote_document_cache.ts @@ -63,24 +63,27 @@ export class IndexedDbRemoteDocumentCache implements RemoteDocumentCache { maybeDocuments: MaybeDocument[] ): PersistencePromise { const promises: Array> = []; - const documentStore = remoteDocumentsStore(transaction); - let changedKeys = documentKeySet(); - for (const maybeDocument of maybeDocuments) { + if (maybeDocuments.length > 0) { + const documentStore = remoteDocumentsStore(transaction); + let changedKeys = documentKeySet(); + for (const maybeDocument of maybeDocuments) { + promises.push( + documentStore.put( + dbKey(maybeDocument.key), + this.serializer.toDbRemoteDocument(maybeDocument) + ) + ); + changedKeys = changedKeys.add(maybeDocument.key); + } + promises.push( - documentStore.put( - dbKey(maybeDocument.key), - this.serializer.toDbRemoteDocument(maybeDocument) - ) + documentChangesStore(transaction).put({ + changes: this.serializer.toDbResourcePaths(changedKeys) + }) ); - changedKeys = changedKeys.add(maybeDocument.key); } - promises.push( - documentChangesStore(transaction).put({ - changes: this.serializer.toDbResourcePaths(changedKeys) - }) - ); return PersistencePromise.waitFor(promises); }