Commit 50b02d6
Move calls to Patient Updaters outside transaction
Previously `PatientTeamUpdater.call` & `PatientStatusUpdater.call` were being
called from `ImmunisationImport#postprocess_rows!` which was inside the
transaction initiated in `ImmunisationImport#process!`. Since both of these
Updaters are just updating a set of records that are effectively a "cache",
they don't need to run inside the transaction.
The `PatientStatusUpdater` in particular can end up UPSERTing a significant
number of records, so it seems sensible to do that outside the transaction to
reduce the time the transaction takes and reduces the number of records locked
by the transaction. This should reduce the chances of other transactions being
blocked by an `ImmunisationImport` transaction.
The reason the transaction is needed in `ImmunisationImport#process!` is that
it's UPSERTing into a bunch of related tables and JOIN tables via
`ImmunisationImport#bulk_import` and if an exception occurs in the middle of
this, we need to rollback to a consistent state. In contrast the Updaters are
UPSERTing records into the "cache" tables and if an exception occurs in the
middle of this, there's no need to rollback; the `ImmunisationImport` will fail
and when it is eventually run again, the Updaters will be run again and the
"cache" will be fully updated. So there's no need wrap them in a transaction of
their own.
Co-authored-by: Chris Lowis <chris.lowis@gofreerange.com>1 parent 5ab5fdc commit 50b02d6
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
214 | 215 | | |
| 216 | + | |
215 | 217 | | |
216 | 218 | | |
217 | | - | |
218 | 219 | | |
219 | | - | |
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| |||
0 commit comments