diff --git a/AUTHORS.rst b/AUTHORS.rst index 02e644c43..fcf285f71 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -16,6 +16,7 @@ Authors - Alexander Anikeev - Amanda Ng (`AmandaCLNg `_) - Amartis Gladius (`Amartis `_) +- Anton Kulikov (`bigtimecriminal `_) - Ben Lawson (`blawson `_) - Benjamin Mampaey (`bmampaey `_) - Bheesham Persaud (`bheesham `_) diff --git a/CHANGES.rst b/CHANGES.rst index 559bc6976..0279c0dca 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------ diff --git a/simple_history/management/commands/clean_duplicate_history.py b/simple_history/management/commands/clean_duplicate_history.py index bbbd17e4c..786be6a11 100644 --- a/simple_history/management/commands/clean_duplicate_history.py +++ b/simple_history/management/commands/clean_duplicate_history.py @@ -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