Skip to content

[Multi-Tab] Don't add change log entry when there are no changes #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions packages/firestore/src/local/indexeddb_remote_document_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,27 @@ export class IndexedDbRemoteDocumentCache implements RemoteDocumentCache {
maybeDocuments: MaybeDocument[]
): PersistencePromise<void> {
const promises: Array<PersistencePromise<void>> = [];
const documentStore = remoteDocumentsStore(transaction);

let changedKeys = documentKeySet();
for (const maybeDocument of maybeDocuments) {
if (maybeDocuments.length > 0) {
const documentStore = remoteDocumentsStore(transaction);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine... but why are we calling addEntries() with an empty list anyway? Should we be filtering this out at a higher-level (potentially preventing even more unnecessary work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was pondering about doing this one layer up, but ended up picking the remote_document_cache for no particular reason (other than this would solve the same problem no matter who calls addEntries). Leaving as is.

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);
}

Expand Down