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

Replace expensive count() with cheap exists() #478

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Replace expensive count() with cheap exists() #478

merged 1 commit into from
Jun 3, 2024

Conversation

tuky
Copy link
Contributor

@tuky tuky commented May 13, 2024

Heyo, hopefully an easy one. We are using model bakery in a setting where the DB can have millions of rows and counting the table just for checking, if any entry exists is overkill. The easy solution: only check for existence.

@tuky tuky changed the title Replace expansive count() with cheap exists() Replace expensive count() with cheap exists() May 13, 2024
Copy link
Member

@berinhard berinhard left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to open this PR, @tuky! This is definitely a significant improvement for large DBs.

@tuky
Copy link
Contributor Author

tuky commented May 14, 2024

Thx. Yeah, it's especially an improvement for MySQL InnoDB like we run 😏

@amureki
Copy link
Collaborator

amureki commented Jun 3, 2024

@tuky great catch here! Thanks for the contribution!

@amureki amureki merged commit 1899c19 into model-bakers:main Jun 3, 2024
9 checks passed
@tuky tuky deleted the patch-2 branch June 6, 2024 20:35
amureki added a commit that referenced this pull request Aug 9, 2024
* origin/main:
  Bump 1.19.0
  Fix #483 -- Add Django 5.1 support (#485)
  Bump 1.18.3
  Refs #416 -- Allow combination of GFK and `_fill_optional` (#438)
  Bump 1.18.2
  Update ruff CI syntax (#481)
  Fix #28 -- allow make_recipe to work with _quantity (#480)
  Bump 1.18.1
  Replace expensive `count()` with cheap `exists()` (#478)
  Update CI Python version to 3.12
  Delete hard action requirement for a changelog
  Bump 1.18.0
  Fix #265 -- drop hard dependency on `contenttypes` framework (#476)
  Bump GitHub Actions artifacts to v4 (#470)
  Drop Django 3.2 support (#475)
  Bump actions/setup-python from 4 to 5 (#466)
  Drop Django 4.1 support (reached end of life) (#465)
  Support Django 5.0 (#464)
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.

3 participants