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
Use IndexedDB indexes on gatherLocalChanges() #315
Conversation
@@ -205,12 +205,30 @@ export default class IDB extends BaseAdapter { | |||
* @override | |||
* @return {Promise} | |||
*/ | |||
list() { | |||
list(params={}) { |
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.
we should provide default property values for the params object; eg Object.keys(params.filters)
can fail when no filters
object is provided.
c29d855
to
6cb2f66
Compare
return Promise.all([ | ||
this.list({order: "", filters: {_status: "deleted"}}, {includeDeleted: true}), | ||
this.list({order: "", filters: {_status: "synced"}}, {includeDeleted: true}), | ||
]) |
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: refactoring suggestion:
const listStatus = (_status) => {
return this.list({order: "", filters: {_status}}, {includeDeleted: true});
};
return Promise.all([listStatus("deleted"), listStatus("synced")])
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 we're using the same query type later, we could even extract the function as something reusable:
function listStatus(coll, status, options={includeDeleted: true}) {
return coll.list({order: "", filters: {_status: status}}, options);
};
Or if we want to pick all records matching provided statuses:
function listStatuses(coll, statuses, options={includeDeleted: true}) {
return Promise.all(statuses.map(status => {
return coll.list({order: "", filters: {_status: status}}, options);
})).then((...results) => [].concat.apply([], results));
};
Usage:
return listStatuses(this, ["deleted", "synced"]);
Optimized synchronization at several places: - during scan of un-synced records - when no change was made on server In terms of API, the adapters are now in charge of adapting #list() parameters (filters and sort). This PR does not break any API, the filtering and sorting is done like before using a reduce from utils.js
fcb2a4a
to
9c19c10
Compare
Ready for review/merge. |
@@ -205,12 +206,33 @@ export default class IDB extends BaseAdapter { | |||
* @override | |||
* @return {Promise} | |||
*/ | |||
list() { | |||
list(params={filters: {}, order: ""}) { |
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't we simply avoid passing order
here?
r+ |
Use IndexedDB indexes on gatherLocalChanges()
Small benchmark: 4500 records in local store. None of them changed.
Before (1000+):
After (<50):