From 53e27efef22c02c89407a0ba8f320fec7e6b4bf7 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 21 Jul 2022 11:02:38 -0700 Subject: [PATCH 1/2] Use exists query instead of count in clean-duplicate_history command. --- AUTHORS.rst | 1 + CHANGES.rst | 1 + .../management/commands/clean_duplicate_history.py | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 0cc8502d9..bc5eaf2ef 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 `_) - `bradford281 `_ diff --git a/CHANGES.rst b/CHANGES.rst index 344dc8d7e..51ea91166 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changes Unreleased ---------- +- Started using ``exists`` query instead of ``count`` in ``clean-duplicate_history`` command - Fixed typos in the docs - Removed n+1 query from ``bulk_create_with_history`` utility (gh-975) - Started using ``exists`` query instead of ``count`` in ``populate_history`` command (gh-982) diff --git a/simple_history/management/commands/clean_duplicate_history.py b/simple_history/management/commands/clean_duplicate_history.py index 298238d80..59ff2be74 100644 --- a/simple_history/management/commands/clean_duplicate_history.py +++ b/simple_history/management/commands/clean_duplicate_history.py @@ -66,9 +66,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 From bf8bfd2beda7f4d6a21c963c929e773d59e39953 Mon Sep 17 00:00:00 2001 From: Anders <6058745+ddabble@users.noreply.github.com> Date: Thu, 28 Sep 2023 18:38:32 +0200 Subject: [PATCH 2/2] Improved changelog for #1015 --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index d683fc044..0279c0dca 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +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) -- Started using ``exists`` query instead of ``count`` in ``clean-duplicate_history`` command +- Small performance optimization of the ``clean-duplicate_history`` command (gh-1015) 3.4.0 (2023-08-18) ------------------