-
Notifications
You must be signed in to change notification settings - Fork 938
Update query-document mapping from bundles. #3620
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
Changes from 3 commits
7d808c1
d62f9cc
b00494e
e2f17ca
322e27d
1d5a4a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1249,6 +1249,30 @@ export async function ignoreIfPrimaryLeaseLoss( | |
} | ||
} | ||
|
||
export function getQueryDocumentMapping( | ||
localStore: LocalStore, | ||
documents: BundledDocuments | ||
): Map<string, DocumentKeySet> { | ||
const localStoreImpl = debugCast(localStore, LocalStoreImpl); | ||
const queryDocumentMap = new Map<string, DocumentKeySet>(); | ||
const bundleConverter = new BundleConverter(localStoreImpl.serializer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to get the serializer from the callsite of this function, drop its dependency on "LocalStore" and move it to bundle.ts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to add a |
||
for (const bundleDoc of documents) { | ||
if (bundleDoc.metadata.queries) { | ||
const documentKey = bundleConverter.toDocumentKey( | ||
bundleDoc.metadata.name! | ||
); | ||
for (const queryName of bundleDoc.metadata.queries) { | ||
const documentKeys = ( | ||
queryDocumentMap.get(queryName) || documentKeySet() | ||
).add(documentKey); | ||
queryDocumentMap.set(queryName, documentKeys); | ||
} | ||
} | ||
} | ||
|
||
return queryDocumentMap; | ||
} | ||
|
||
/** | ||
* Applies the documents from a bundle to the "ground-state" (remote) | ||
* documents. | ||
|
@@ -1300,6 +1324,9 @@ export function applyBundleDocuments( | |
txn, | ||
changedDocs | ||
); | ||
}) | ||
.next(changedDocuments => { | ||
return PersistencePromise.resolve(changedDocuments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a no-op. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
}); | ||
} | ||
); | ||
|
@@ -1373,7 +1400,8 @@ export function getNamedQuery( | |
*/ | ||
export async function saveNamedQuery( | ||
localStore: LocalStore, | ||
query: bundleProto.NamedQuery | ||
query: bundleProto.NamedQuery, | ||
documents: DocumentKeySet = documentKeySet() | ||
): Promise<void> { | ||
// Allocate a target for the named query such that it can be resumed | ||
// from associated read time if users use it to listen. | ||
|
@@ -1389,21 +1417,41 @@ export async function saveNamedQuery( | |
'readwrite', | ||
transaction => { | ||
// Update allocated target's read time, if the bundle's read time is newer. | ||
let updateReadTime = PersistencePromise.resolve(); | ||
let updateReadTime = PersistencePromise.resolve(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If still needed: s/updateReadTime/updatedReadTime (or readTimeUpdated) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
const readTime = fromVersion(query.readTime!); | ||
if (allocated.snapshotVersion.compareTo(readTime) < 0) { | ||
const newTargetData = allocated.withResumeToken( | ||
ByteString.EMPTY_BYTE_STRING, | ||
readTime | ||
); | ||
updateReadTime = localStoreImpl.targetCache.updateTargetData( | ||
transaction, | ||
updateReadTime = localStoreImpl.targetCache | ||
.updateTargetData(transaction, newTargetData) | ||
.next( | ||
() => true, | ||
() => false | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs explanation (but I think it could be removed if you update the target mapping right here) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
localStoreImpl.targetDataByTarget = localStoreImpl.targetDataByTarget.insert( | ||
newTargetData.targetId, | ||
newTargetData | ||
); | ||
} | ||
return updateReadTime.next(() => | ||
localStoreImpl.bundleCache.saveNamedQuery(transaction, query) | ||
); | ||
return updateReadTime | ||
.next(updated => { | ||
if (updated) { | ||
return localStoreImpl.targetCache | ||
.removeMatchingKeysForTargetId(transaction, allocated.targetId) | ||
.next(() => | ||
localStoreImpl.targetCache.addMatchingKeys( | ||
transaction, | ||
documents, | ||
allocated.targetId | ||
) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this not just be chained off the call to "updateTargetData"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
}) | ||
.next(() => | ||
localStoreImpl.bundleCache.saveNamedQuery(transaction, query) | ||
); | ||
} | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Empty line below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.