Skip to content

Commit

Permalink
Use exists query instead of count in clean-duplicate-history command. (
Browse files Browse the repository at this point in the history
…#1015)

* Use exists query instead of count in clean-duplicate_history command.

* Improved changelog for #1015

---------

Co-authored-by: Anders <[email protected]>
  • Loading branch information
Anton and ddabble authored Sep 28, 2023
1 parent fd9aa52 commit 0fc4686
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
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

0 comments on commit 0fc4686

Please sign in to comment.