Skip to content

Commit

Permalink
fix: Avoid fallback to existing jobs index
Browse files Browse the repository at this point in the history
  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 avoid this fallback we will sort on a second attribute not present
  in the existing `cozy-stack` index: `message.slug`.
  • Loading branch information
taratatach committed Apr 4, 2023
1 parent 15f54af commit de65194
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 de65194

Please sign in to comment.