-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: Make PouchLink querying system compatible with new PouchDB version #1506
Conversation
33d9442
to
1049c10
Compare
a787e89
to
642ae2d
Compare
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
1049c10
to
b82c1a6
Compare
642ae2d
to
35ba7ed
Compare
* @param {string} [indexOption.doctype] - doctype | ||
* @returns {Promise<import('./types').PouchDbIndex>} | ||
*/ | ||
async createIndex(fields, { partialFilter, indexName, doctype } = {}) { |
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 don't think the doctype should be an option, as the function cannot work without it
findExistingIndex(doctype, options, indexName) { | ||
const absName = `${doctype}/${indexName}` | ||
return this.indexes[absName] | ||
} |
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 know this method name is copied on the one in DocumentCollection, but I feel like it is a bit deceptive here regarding its name: it checks if we have the index in memory, but if it is not found, it does not mean the index does not exist.
And if it's not found, we create the index: about that did we check that pouchdb correctly handle a creation of an existing index (i.e. it won't recreate the index) ? I think we did, but I'm not entirely sure 😄
In any case, I think we should:
- either rename this function in something like
hasIndexInMemory
, either document a bit more the behaviour - add some comment in the index creation to specify that the creation of an exiting index will not recreate it
indexName: 'by_myIndex', | ||
partial_filter_selector: undefined | ||
} | ||
}) |
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 might be worth adding a simple test with an actual partialFilter
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 in #1524
if (indexedFields) { | ||
for (const indexedField of indexedFields) { | ||
if (!Object.keys(selector).includes(indexedField)) { | ||
selector[indexedField] = { |
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 feel like we should add a warning here, that we do some magic to please pouchdb but that ideally the query should be fixed
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.
And we probably should extract this logic into a function with a test 😉
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 in #1524
findSelector['_id'] = { | ||
$gt: 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.
You don't need to force the _id
selector if the mechanism on line 566-567 added a predicate.
Thus, we might refacto like this:
let findSelector = selector || {}
// ...do the stuff on lines 566...
findSelector = Object.keys(selector).length > 0 ? findSelector : { _id: { $gt: null } } // PouchDB does not accept empty selector
And this whole behavior should definitely be tested, as suggested in my previous 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.
Done in #1524
return normalizedDoc | ||
} | ||
|
||
const normalizeLinks = (docRef, doctype, client) => { | ||
if (doctype !== 'io.cozy.apps') { |
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 guess the function is more normalizeAppsLinks
, then?
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 in #1524
const filterDeletedDocumentsFromRows = doc => !!doc | ||
|
||
export const fromPouchResult = (res, withRows, doctype) => { | ||
export const fromPouchResult = (res, withRows, doctype, client) => { |
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: When dealing with many params, I prefer a ({param1, param2,...})
API
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 in #1524
@@ -96,6 +96,7 @@ class PouchLink extends CozyLink { | |||
this.storage = new PouchLocalStorage( | |||
options.platform?.storage || platformWeb.storage | |||
) | |||
this.ignoreWarmup = ignoreWarmup |
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 we don't specify any warmup query, this is useless, right?
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 in #1524
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
We want to extract this code logic into its own method in order to ease readability and testing Also we refactored the code to make it easier to read This replies to #1506 (comment)
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
We want to extract this code logic into its own method in order to ease readability and testing Also we refactored the code to make it easier to read This replies to #1506 (comment)
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
b82c1a6
to
c8ab4c7
Compare
When we implemented CozyPouchLink, PouchDB did not support partial indexes and so we implemented `mergePartialIndexInSelector` to adapt the query and simulate partial filters Today, when using PouchDB 8 then partial indexes are supported So we don't need `mergePartialIndexInSelector` anymore and we want to use the native implementation instead
`DocumentCollection.handleMissingIndex()` and `CozyPouchLink.ensureIndex()` have nearly identical logic with only a few changes To emphasize those changes, we want to homogenize the code logic between those two methods so their structure will be similar enough to be compared partial index tests
We want to extract this code logic into its own method in order to ease readability and testing Also we refactored the code to make it easier to read This replies to #1506 (comment)
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
We want to extract this code logic into its own method in order to ease readability and testing Also we refactored the code to make it easier to read This replies to #1506 (comment)
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
We want to extract this code logic into its own method in order to ease readability and testing Also we refactored the code to make it easier to read This replies to #1506 (comment)
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
We want to extract this code logic into its own method in order to ease readability and testing Also we refactored the code to make it easier to read This replies to #1506 (comment)
Previous implementation was from a misunderstanding of CozyPouchLink mechanisms As we don't need to specify warmup queries in CozyPouchLink instanciation, we don't need the `ignoreWarmup` as we would result to the same behavior of having no warmup queries Warmup queries concept is meant to be removed into the future as we won't be able to use them when offline and the scenario that needed them (cozy-banks and cozy-drive apps) does not exist anymore This replies to #1506 (comment) Related commit: bb43ae9
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
With previous changes, we now expect the CozyPouchLink to be the last link of the chain, so forwarding the query would result to an exception thrown This mean we cannot forward the query when warmup queries are not finished yet So we want to allow CozyPouchLink to ignore the verification step and process the query independently of the warmup queries status To allow this we introduce the `ignoreWarmup` parameter. When set to `true` the CozyPouchLink will process the query even if warmup is not finished yet Related PR: cozy/cozy-client#1506
In previous PRs we modified cozy-client and cozy-pouch-link to make them compatible with the react-native Flagship app
Since we didn't use this link for a long time but also because we use a newer PouchDB version, some queries do not work anymore (i.e. incompatible indexes, bad selectors etc)
This PR improve PouchLink querying system to make our app ecosystem compatible with new PouchDB version