Skip to content

Integrate Document Overlay with the SDK #6123

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 11 commits into from
Apr 6, 2022
Merged
9 changes: 9 additions & 0 deletions packages/firestore/src/local/document_overlay_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export interface DocumentOverlayCache {
key: DocumentKey
): PersistencePromise<Overlay | null>;

/**
* Gets the saved overlay mutation for the given document keys. Skips keys for
* which there are no overlays.
*/
getOverlays(
transaction: PersistenceTransaction,
keys: DocumentKeySet
): PersistencePromise<OverlayMap>;

/**
* Saves the given document mutation map to persistence as overlays.
* All overlays will have their largest batch id set to `largestBatchId`.
Expand Down
18 changes: 18 additions & 0 deletions packages/firestore/src/local/indexeddb_document_overlay_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
});
}

getOverlays(
transaction: PersistenceTransaction,
keys: DocumentKeySet
): PersistencePromise<OverlayMap> {
const result = newOverlayMap();
const promises: Array<PersistencePromise<void>> = [];
keys.forEach(key => {
promises.push(
this.getOverlay(transaction, key).next(overlay => {
if (overlay !== null) {
result.set(key, overlay);
}
})
);
});
return PersistencePromise.waitFor(promises).next(() => result);
}

saveOverlays(
transaction: PersistenceTransaction,
largestBatchId: number,
Expand Down
Loading