Skip to content
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

Merged
merged 10 commits into from
Sep 9, 2024

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Jul 26, 2024

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

@Ldoppea Ldoppea force-pushed the feat/add_flagshiplink branch from 33d9442 to 1049c10 Compare July 26, 2024 15:04
@Ldoppea Ldoppea force-pushed the featt/implement_flagship_link branch 2 times, most recently from a787e89 to 642ae2d Compare July 30, 2024 16:39
@Ldoppea Ldoppea marked this pull request as ready for review July 30, 2024 16:42
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jul 30, 2024
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
@Ldoppea Ldoppea force-pushed the feat/add_flagshiplink branch from 1049c10 to b82c1a6 Compare August 13, 2024 15:31
@Ldoppea Ldoppea force-pushed the featt/implement_flagship_link branch from 642ae2d to 35ba7ed Compare August 13, 2024 15:31
* @param {string} [indexOption.doctype] - doctype
* @returns {Promise<import('./types').PouchDbIndex>}
*/
async createIndex(fields, { partialFilter, indexName, doctype } = {}) {
Copy link
Contributor

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]
}
Copy link
Contributor

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
}
})
Copy link
Contributor

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

Copy link
Member Author

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] = {
Copy link
Contributor

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

Copy link
Contributor

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 😉

Copy link
Member Author

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
}
}
Copy link
Contributor

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 😉

Copy link
Member Author

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') {
Copy link
Contributor

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?

Copy link
Member Author

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) => {
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #1524

Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
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
Ldoppea added a commit that referenced this pull request Sep 4, 2024
Ldoppea added a commit that referenced this pull request Sep 4, 2024
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)
Ldoppea added a commit that referenced this pull request Sep 4, 2024
Ldoppea added a commit that referenced this pull request Sep 4, 2024
Ldoppea added a commit that referenced this pull request Sep 4, 2024
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
Ldoppea added a commit that referenced this pull request Sep 4, 2024
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
Ldoppea added a commit that referenced this pull request Sep 5, 2024
Ldoppea added a commit that referenced this pull request Sep 5, 2024
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)
Ldoppea added a commit that referenced this pull request Sep 5, 2024
Ldoppea added a commit that referenced this pull request Sep 5, 2024
Ldoppea added a commit that referenced this pull request Sep 5, 2024
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
@Ldoppea Ldoppea force-pushed the feat/add_flagshiplink branch from b82c1a6 to c8ab4c7 Compare September 9, 2024 12:57
Base automatically changed from feat/add_flagshiplink to feat/meta_offline September 9, 2024 13:14
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
Ldoppea added a commit that referenced this pull request Sep 19, 2024
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)
Ldoppea added a commit that referenced this pull request Sep 19, 2024
Ldoppea added a commit that referenced this pull request Sep 19, 2024
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
Ldoppea added a commit that referenced this pull request Sep 19, 2024
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)
Ldoppea added a commit that referenced this pull request Sep 19, 2024
Ldoppea added a commit that referenced this pull request Sep 19, 2024
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
Ldoppea added a commit that referenced this pull request Sep 24, 2024
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)
Ldoppea added a commit that referenced this pull request Sep 24, 2024
Ldoppea added a commit that referenced this pull request Sep 24, 2024
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
Ldoppea added a commit that referenced this pull request Sep 24, 2024
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)
Ldoppea added a commit that referenced this pull request Sep 24, 2024
Ldoppea added a commit that referenced this pull request Sep 24, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Sep 24, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Sep 24, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Sep 25, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Nov 12, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 11, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 11, 2024
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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 19, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants