Changes between Initial Version and Version 1 of Ticket #33937
- Timestamp:
- Aug 18, 2022, 8:15:56 AM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33937
- Property Triage Stage Unreviewed → Accepted
- Property Summary Serialize is loading full objects when serializing m2m fields. → Optimize m2m serialization to avoid loading full model instances
- Property Type Uncategorized → Cleanup/optimization
-
Ticket #33937 – Description
initial v1 1 When not using natural keys, th is function https://github.com/django/django/blob/main/django/core/serializers/python.py#L64 loads the full object for every entry in the m2m, when it only actually wants the pks which it could get off the m2m intermediate table without even joining tothe target table.1 When not using natural keys, the `handle_m2m_field` function([https://github.com/django/django/blob/aed60aee38215e293d6ec2f3c96ec55bb9a62fc2/django/core/serializers/python.py#L64 source]) loads the full object for every entry in the m2m model, when it only needs the pks. The pk's can even be obtained from the m2m intermediate table, without joining the target table. 2 2 3 3 In my case the table we are m2m'ing to has files in it, so that's a weighty fetch.