-
-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating M2M relations causes unnecessary DB queries #1317
Comments
I'm not sure I'm able to reproduce your issue 🤔 Calling e.g. |
This is not about duplicate records, but duplicate database queries, as identified by e.g. Django Debug Toolbar. It’s a performance issue. Can you also see duplicate queries by inspecting with debug toolbar? If not, I’ll try and make a test case. |
Ah, sorry, I misread your description 😅 I'm able to reproduce it, and will open a PR for it :) |
Thank you, lovely to hear! Let me know if I can help in any way. |
Any update on this? |
I've made a fix for it locally, but considering that @tim-schilling and I are the only currently active maintainers, I want to focus on finishing #1128 first, which seems close to being merged 🙂 |
@alimony if this is an urgent thing for you, please write the test case and attempt a fix. Anything that gets things started will help tremendously. |
Thanks a lot @ddabble ! |
@ddabble Any idea when we might see this in a release? |
I'm planning on creating a new release after #1344 has been merged 🙂 |
If I have the models e.g.
User
andGroup
whereGroup
has an m2m field toUser
and also has a field likehistory = HistoricalRecords(m2m_fields=[users])
, calling any of the m2m set update methods such asgroup.users.set(users)
orgroup.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 theGroup
model as suggested by the documentation, but related sets seem unaffected by this.The text was updated successfully, but these errors were encountered: