update_or_create should utilize update_fields on update
update_or_create should update only the fields in default on update, not all fields. While it is concurrency-safe to update the whole model since update_or_create fetches the object via select_for_update it is still unnecessary to re transmit all fields back to the database (probably results in more wal/binary logs written etc etc…).
In the end update_or_create (and most likely get_or_create) might be written in more efficient ways depending on the database backend -- but update_fields seems to be a rather low-hanging fruit.
Change History
(13)
| Component: |
Uncategorized → Database layer (models, ORM)
|
| Triage Stage: |
Unreviewed → Accepted
|
| Type: |
Uncategorized → Cleanup/optimization
|
| Owner: |
changed from nobody to Liel Fridman
|
| Status: |
new → assigned
|
| Has patch: |
set
|
| Owner: |
changed from Liel Fridman to Florian Apolloner
|
| Patch needs improvement: |
set
|
| Owner: |
changed from Florian Apolloner to Sarah Boyce
|
| Patch needs improvement: |
unset
|
| Patch needs improvement: |
set
|
| Patch needs improvement: |
unset
|
| Patch needs improvement: |
set
|
| Patch needs improvement: |
unset
|
| Triage Stage: |
Accepted → Ready for checkin
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
It could have a noticeable impact on PostgreSQL to not update these columns in some scenario as are they are likely to be indexed if matched against (Write Amplification problem)