Skip to content
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

Fix O(n) queries when adding M2M objects #1333

Merged
merged 1 commit into from
May 15, 2024
Merged

Conversation

ddabble
Copy link
Member

@ddabble ddabble commented May 15, 2024

Description

For history-tracked M2M fields, adding M2M objects (using add() or set()) used to cause a number of database queries that scaled linearly with the number of objects (O(n)); this has been fixed to now be a constant number of queries (O(1)).

Related Issue

Resolves #1317.

Motivation and Context

See linked issue.

How Has This Been Tested?

See the added test.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run the pre-commit run command to format and lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

@ddabble ddabble requested a review from tim-schilling May 15, 2024 01:29
Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.84%. Comparing base (733f4e0) to head (a089803).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1333      +/-   ##
==========================================
+ Coverage   96.83%   96.84%   +0.01%     
==========================================
  Files          24       24              
  Lines        1452     1457       +5     
  Branches      237      240       +3     
==========================================
+ Hits         1406     1411       +5     
  Misses         24       24              
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

@ddabble ddabble merged commit e9689f8 into master May 15, 2024
40 checks passed
@ddabble ddabble deleted the fix/too-many-m2m-queries branch May 15, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating M2M relations causes unnecessary DB queries
2 participants