Skip to content

Commit

Permalink
fix: Create proper in-progress export jobs query (#2630)
Browse files Browse the repository at this point in the history
Backport of #2627 

We have 2 issues with the current in-progress export jobs query:
- not setting the indexed fields ourselves is not compatible with the 
  use of an `$or` operator (see 
  cozy/cozy-client#1270)
- the index is not created if there are too many jobs in the db

Luckily these can be fixed by using the `indexFields()` and `sortBy()` 
method of `cozy-client`'s `QueryDefinition` object.
See the commits messages for more details.

```
### 🐛 Bug Fixes

* Create proper, optimized query for in-progress export jobs
```
  • Loading branch information
taratatach authored Mar 17, 2023
1 parent 635dbe8 commit de1ffee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ducks/export/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import { JOBS_DOCTYPE } from 'doctypes'
export const isExportJobInProgress = async client => {
const { data } = await client.query(
Q(JOBS_DOCTYPE)
.where({
.partialIndex({
worker: 'service',
message: {
slug: 'banks',
name: 'export'
}
})
.partialIndex({
},
$or: [{ state: 'queued' }, { state: 'running' }]
})
.indexFields(['worker'])
.sortBy([{ worker: 'asc' }]) // XXX: forces CouchDB to require an index for the query
.limitBy(1)
)

Expand Down

0 comments on commit de1ffee

Please sign in to comment.