Skip to content

Updating M2M relations causes unnecessary DB queries #1317

@alimony

Description

@alimony

If I have the models e.g. User and Group where Group has an m2m field to User and also has a field like history = HistoricalRecords(m2m_fields=[users]), calling any of the m2m set update methods such as group.users.set(users) or group.users.add(user1, user2) causes duplicate queries.

I have an example of this where I add 25 users to a group, and it generates 25 extra user selects and 25 extra group selects.

Is there any way to work around this? Since I do this right after creating a new Group, I tried bypassing history saving on the Group model as suggested by the documentation, but related sets seem unaffected by this.

Metadata

Metadata

Assignees

Labels

acceptedIssue accepted for completionbugIssues related to confirmed bugs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions