Skip to content

Commit 104964e

Browse files
ehsannasdconeybe
andauthored
Integrate Document Overlay with the SDK (#6123)
* Integrate Document Overlay with the SDK. * we should call ObjectValue.delete if value is null. * Remove unnecessary null check from MemoryDocumentOverlayCache.saveOverlay(), like is done in firebase/firebase-android-sdk#3518 * Address comments. * Port changes from Android SDK PR#3420. Note that we are not going to do any processing in the background. * Port overlay recalculation bug (Android SDK PR #3495). * Fix overlay bug when offline (Port Android SDK PR #3537). * Address feedback. * Better null check. Co-authored-by: Denver Coneybeare <[email protected]>
1 parent d756f4e commit 104964e

17 files changed

+1351
-223
lines changed

packages/firestore/src/local/document_overlay_cache.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ export interface DocumentOverlayCache {
4343
key: DocumentKey
4444
): PersistencePromise<Overlay | null>;
4545

46+
/**
47+
* Gets the saved overlay mutation for the given document keys. Skips keys for
48+
* which there are no overlays.
49+
*/
50+
getOverlays(
51+
transaction: PersistenceTransaction,
52+
keys: DocumentKeySet
53+
): PersistencePromise<OverlayMap>;
54+
4655
/**
4756
* Saves the given document mutation map to persistence as overlays.
4857
* All overlays will have their largest batch id set to `largestBatchId`.

packages/firestore/src/local/indexeddb_document_overlay_cache.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
8181
});
8282
}
8383

84+
getOverlays(
85+
transaction: PersistenceTransaction,
86+
keys: DocumentKeySet
87+
): PersistencePromise<OverlayMap> {
88+
const result = newOverlayMap();
89+
const promises: Array<PersistencePromise<void>> = [];
90+
keys.forEach(key => {
91+
promises.push(
92+
this.getOverlay(transaction, key).next(overlay => {
93+
if (overlay !== null) {
94+
result.set(key, overlay);
95+
}
96+
})
97+
);
98+
});
99+
return PersistencePromise.waitFor(promises).next(() => result);
100+
}
101+
84102
saveOverlays(
85103
transaction: PersistenceTransaction,
86104
largestBatchId: number,

0 commit comments

Comments
 (0)