Skip to content

Commit

Permalink
fix: Prevent fallback to existing jobs index (#2648)
Browse files Browse the repository at this point in the history
Backport of #2644 

The in-progress jobs query for the export feature relies on the
presence of a very specific index to be fast on cozies with a lot of
`io.cozy.jobs` documents.

To make sure the index presence detection goes well, we forced a sort
on the `worker` attribute.
However, since `cozy-stack` uses an index on `worker` and `state`
only, CouchDB fallbacks to this index instead of detecting the index
we want does not exist and runs the slow `$or` query in-memory.
See apache/couchdb#4511 for more details on
this issue.

To prevent this fallback we will sort on a second attribute not present
in the existing `cozy-stack` index: `message.slug`.

```
### 🐛 Bug Fixes

* Prevent fallback on sub-optimal index for in-progress jobs query.
```
  • Loading branch information
taratatach committed Apr 5, 2023
1 parent 95a9b0a commit 6d0bff0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ducks/export/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const isExportJobInProgress = async client => {
},
$or: [{ state: 'queued' }, { state: 'running' }]
})
.indexFields(['worker'])
.sortBy([{ worker: 'asc' }]) // XXX: forces CouchDB to require an index for the query
.indexFields(['worker', 'message.slug'])
.sortBy([{ worker: 'asc' }, { 'message.slug': 'asc' }]) // XXX: forces CouchDB to require an index for the query
.limitBy(1)
)

Expand Down

0 comments on commit 6d0bff0

Please sign in to comment.