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

Meta-Issue : Index Names & MatchingIndex #1374

Open
1 of 4 tasks
Crash-- opened this issue Jul 27, 2023 · 0 comments
Open
1 of 4 tasks

Meta-Issue : Index Names & MatchingIndex #1374

Crash-- opened this issue Jul 27, 2023 · 0 comments

Comments

@Crash--
Copy link
Contributor

Crash-- commented Jul 27, 2023

The idea of this issue is to regroup all the work we done / we have to do, in order to handle correctly the indexes on Cozy-Client.

We have two issues with indexes in Cozy-Client:
The first one is related to the usage of logical mango operators ($or, $and, $in, etc.) at the top level.Cozy-Client doesn't handle them properly and creates indexes named $or/$and/$etc
(see #1270). This can lead to conflicts with the indexes.
Even worse, when we create a partialFilter without declaring a top-level $and, like [{foo: bar, truc:muche}], the index name on the Cozy-Client side is correct (foo_truc). However, when we inspect the design doc, CouchDB automatically adds the $and, and it becomes $and: [{foo: bar}, {truc: muche}]
The second issue is the automatic deletion of what Cozy-Client considers "inconsistent" indexes. When Cozy-Client receives an event of type index_not_found or not_usable_index, it performs some leanup by querying all the indexes on the relevant doctype and checks if the index name matches the indexed fields in the design doc. Due to CouchDB's automatic addition of a top-level logical operator with an implicit $and, Cozy-Client doesn't handle this well and considers the index as "inconsistent," leading to its deletion.
The real solution is to make Cozy-Client capable of handling logical operators at the top level of indexes / partialFilters. To achieve this, we need to rename all the indexes. However, doing so would result in the deletion of indexes judged inconsistent by the current Cozy-Client version. Newer versions of Cozy-Client will create new, correct indexes, but older apps will delete them as they won't correspond to the previous logic. This process of create / delete / create / delete will become a nightmare.

From #1373

Here is the actions we need to take:

  • Remove the destroy of inconsistent index (fix: Stop destroying inconsistent index #1373)
  • Generate the right name for the index, even if there is logical operator in selector and partialFilter
  • Handle logical operator when creating an index (see issue Do not try to index mango operator #1270)
  • Convert implicit operator to explicit since CouchDB does that ([{foo: bar, truc:muche}] becomes $and: [{foo: bar}, {truc: muche}] in the design_doc). As a result, isMatchingIndex cannot function properly.
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

No branches or pull requests

1 participant