-
Notifications
You must be signed in to change notification settings - Fork 92
Improve multiGet, multiSet and multiMerge SQL operations #732
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
base: main
Are you sure you want to change the base?
Improve multiGet, multiSet and multiMerge SQL operations #732
Conversation
| return (result ?? []) as StorageKeyValuePair[]; | ||
| }); | ||
| // For a small number of keys, it's more efficient to just use a single query with multiple placeholders. | ||
| if (keys.length <= 500) { |
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: Maybe we can put 500 into const and add a comment why it's 500, so it doesn't look like magic number
| // FIXME: Not working because of "-" apparently. | ||
| // const tableName = `temp_multiGet_${Str.guid()}`; |
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 something we want to fix later in this PR or in the follow up?
JKobrynski
left a comment
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 agree with Vicky's comments, other than that LGTM!
| // For a large number of keys, it becomes more performant if we insert the keys into a temporary table and perform a join. | ||
| // FIXME: Not working because of "-" apparently. | ||
| // const tableName = `temp_multiGet_${Str.guid()}`; | ||
| const tableName = `temp_multiGet_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`; |
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 we create a helper for the random part?
Also noticed that we use Math.random().toString(36).substring(2, 9) across the codebase - with 9 at the end
| return provider.store | ||
| .executeAsync(`CREATE TEMP TABLE ${tableName} (record_key TEXT PRIMARY KEY);`) | ||
| .then(() => { | ||
| if (!provider.store) { |
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.
do we need this check inside the .then(() that is chained on provider.store ?
I think we need to move this check before return
| return provider.store.executeBatchAsync([{query: insertQuery, params: insertParams}]); | ||
| }) | ||
| .then(() => { | ||
| if (!provider.store) { |
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.
same here
Details
Related Issues
Expensify/App#80243
Automated Tests
Manual Tests
Author Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop