Disabled model auto-refresh when processing email batches

- by default, the model will auto-refresh when you save
- in MySQL, which doesn't support RETURNING, this is implemented by
  doing a SELECT after your actual query
- `email_recipients` is a huge table and `processed_at` is not an
  indexed column, so the query times can become realllyyyyyyy big
- given we don't even need the result of the model save, we can just
  disable fetching all the affected records again
- Bookshelf gives us this ability in the form of `autoRefresh: false`
This commit is contained in:
Daniel Lockyer 2022-05-10 18:03:41 +01:00
parent bb9a797283
commit 1c7d4e49c5
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD

View File

@ -197,7 +197,7 @@ module.exports = {
// update all email recipients with a processed_at
await models.EmailRecipient
.where({batch_id: emailBatchId})
.save({processed_at: moment()}, Object.assign({}, knexOptions, {patch: true}));
.save({processed_at: moment()}, Object.assign({}, knexOptions, {autoRefresh: false, patch: true}));
}
},