Skip to content

Commit 0fc4686

Browse files
Antonddabble
andauthored
Use exists query instead of count in clean-duplicate-history command. (#1015)
* Use exists query instead of count in clean-duplicate_history command. * Improved changelog for #1015 --------- Co-authored-by: Anders <[email protected]>
1 parent fd9aa52 commit 0fc4686

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Authors
1616
- Alexander Anikeev
1717
- Amanda Ng (`AmandaCLNg <https://github.com/AmandaCLNg>`_)
1818
- Amartis Gladius (`Amartis <https://github.com/amartis>`_)
19+
- Anton Kulikov (`bigtimecriminal <https://github.com/bigtimecriminal>`_)
1920
- Ben Lawson (`blawson <https://github.com/blawson>`_)
2021
- Benjamin Mampaey (`bmampaey <https://github.com/bmampaey>`_)
2122
- Bheesham Persaud (`bheesham <https://github.com/bheesham>`_)

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Unreleased
1414
now allowed; history records will still be created (gh-1248)
1515
- Added temporary requirement on ``asgiref>=3.6`` while the minimum required Django
1616
version is lower than 4.2 (gh-1261)
17+
- Small performance optimization of the ``clean-duplicate_history`` command (gh-1015)
1718

1819
3.4.0 (2023-08-18)
1920
------------------

simple_history/management/commands/clean_duplicate_history.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ def _process(self, to_process, date_back=None, dry_run=True):
7474
m_qs = history_model.objects
7575
if stop_date:
7676
m_qs = m_qs.filter(history_date__gte=stop_date)
77-
found = m_qs.count()
78-
self.log(f"{model} has {found} historical entries", 2)
79-
if not found:
77+
if self.verbosity >= 2:
78+
found = m_qs.count()
79+
self.log(f"{model} has {found} historical entries", 2)
80+
if not m_qs.exists():
8081
continue
8182

8283
# Break apart the query so we can add additional filtering

0 commit comments

Comments
 (0)