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

Use exists query instead of count in clean-duplicate-history command. #1015

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Authors
- Alexander Anikeev
- Amanda Ng (`AmandaCLNg <https://github.com/AmandaCLNg>`_)
- Amartis Gladius (`Amartis <https://github.com/amartis>`_)
- Anton Kulikov (`bigtimecriminal <https://github.com/bigtimecriminal>`_)
- Ben Lawson (`blawson <https://github.com/blawson>`_)
- Benjamin Mampaey (`bmampaey <https://github.com/bmampaey>`_)
- Bheesham Persaud (`bheesham <https://github.com/bheesham>`_)
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unreleased
now allowed; history records will still be created (gh-1248)
- Added temporary requirement on ``asgiref>=3.6`` while the minimum required Django
version is lower than 4.2 (gh-1261)
- Small performance optimization of the ``clean-duplicate_history`` command (gh-1015)

3.4.0 (2023-08-18)
------------------
Expand Down
7 changes: 4 additions & 3 deletions simple_history/management/commands/clean_duplicate_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ def _process(self, to_process, date_back=None, dry_run=True):
m_qs = history_model.objects
if stop_date:
m_qs = m_qs.filter(history_date__gte=stop_date)
found = m_qs.count()
self.log(f"{model} has {found} historical entries", 2)
if not found:
if self.verbosity >= 2:
found = m_qs.count()
self.log(f"{model} has {found} historical entries", 2)
if not m_qs.exists():
continue

# Break apart the query so we can add additional filtering
Expand Down