-
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
Update query-document mapping from bundles. #3620
Conversation
💥 No ChangesetLatest commit: 1d5a4a6 Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂 If these changes should be published to npm, you need to add a changeset. This PR includes no changesetsWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Click here to learn what changesets are, and how to add one. Click here if you're a maintainer who wants to add a changeset to this PR |
Binary Size ReportAffected SDKs
Test Logs |
@@ -54,6 +54,9 @@ export interface BundledDocumentMetadata { | |||
|
|||
/** BundledDocumentMetadata exists */ | |||
exists?: boolean | null; | |||
|
|||
/** The names of the queries in this bundle that this document matches to. */ | |||
queries?: string[] | null; |
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.
In Proto3, is not possible to have a missing array. Missing arrays are represented as empty lists, so this should be queries: string[]
.
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.
@@ -1706,6 +1758,69 @@ function genericLocalStoreTests( | |||
.finish(); | |||
}); | |||
|
|||
it('handles loading named queries allocates targets and updates target document mapping', async () => { |
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.
it('handles loading named queries allocates targets and updates target document mapping', async () => { | |
it('loading named queries allocates targets and updates target document mapping', async () => { |
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.
const result = await applyBundleDocuments(this.localStore, this.documents); | ||
|
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.
As far as I can tell, returning the map of matching documents from applyBundleDocuments
saves one iteration. This code would be less complex if you extracted the mapping in this function (ideally, via a call to a helper function). This would remove your changes from applyBundleDocuments
and some of the changes from LocalStoreTester.
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. It IS nicer this way!
const localStoreImpl = debugCast(localStore, LocalStoreImpl); | ||
const bundleConverter = new BundleConverter(localStoreImpl.serializer); | ||
let documentMap = maybeDocumentMap(); | ||
let versionMap = documentVersionMap(); | ||
const queryDocumentMap: Map<string, DocumentKeySet> = new Map(); |
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.
const queryDocumentMap: Map<string, DocumentKeySet> = new Map(); | |
const queryDocumentMap = new Map<string, DocumentKeySet>(); |
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.
localStoreImpl.bundleCache.saveNamedQuery(transaction, query) | ||
) | ||
.next(() => | ||
localStoreImpl.targetCache.addMatchingKeys( |
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.
I think you should only do this if you updated the readTime above. On top of that, you need to also remove all existing keys, otherwise your mapping will not match the backend's mapping.
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.
Agree to both.
const queryDocumentMap = getQueryDocumentMapping( | ||
this.localStore, | ||
this.documents | ||
); |
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.
): 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add a getSerializer
to localstore interface, but that still seems better than current.
.next(changedDocuments => { | ||
return PersistencePromise.resolve(changedDocuments); |
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.
This looks like a no-op.
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.
Fixed.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.next( | ||
() => true, | ||
() => false | ||
); |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
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.
Can you incorporate the following cleanup: https://gist.github.com/schmidt-sebastian/d51c9c9ec7be723fc8f208d69c4bbd9f (it probably needs some fixing)
- It passes in the serializer instead of obtaining it from LocalStore, which improves encapsulation
- It simplifies some of your transaction logic
Applied with some minor fixes. |
); | ||
getSyncEngine(firestoreImpl).then(async syncEngine => { | ||
enqueueLoadBundle( | ||
(await firestoreImpl._getConfiguration()).databaseInfo.databaseId, |
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.
This style of code is pretty hard to debug (a lot of the magic happens inline). Do you mind extracting a local variable for this?
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.
No description provided.