From 5304e46d5d5b5bf7f7ef63420d5f9dc1147306da Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Fri, 30 Oct 2026 10:21:57 -0700 Subject: [PATCH] fix(benchmark): reset SQLite with plain DELETEs instead of ORM deletes The ORM path fires per-document delete signals, which is very slow at the large tier and fails when the cache backend is unreachable. Matches the TRUNCATE-based resets on the other backends. Co-Authored-By: Claude Sonnet 5.5 --- src/paperless_benchmark/db.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/paperless_benchmark/db.py b/src/paperless_benchmark/db.py index cc763c4f3..112004641 100644 --- a/src/paperless_benchmark/db.py +++ b/src/paperless_benchmark/db.py @@ -73,17 +73,14 @@ def _reset_mariadb() -> None: def _reset_sqlite() -> None: - from documents.models import Correspondent - from documents.models import Document - from documents.models import DocumentType - from documents.models import StoragePath - from documents.models import Tag - - Document.global_objects.all().delete() - Tag.objects.all().delete() - Correspondent.objects.all().delete() - DocumentType.objects.all().delete() - StoragePath.objects.all().delete() + # Plain DELETEs, the SQLite equivalent of the TRUNCATEs above. ORM deletes + # fire per-document signals and cascade collection, which is far too slow + # at the large tier and needs the cache backend to be reachable. + # constraint_checks_disabled() mirrors MariaDB's SET FOREIGN_KEY_CHECKS = 0. + tables = _reset_table_names() + with connection.constraint_checks_disabled(), connection.cursor() as cursor: + for table in tables: + cursor.execute(f"DELETE FROM {table};") _delete_all_users_and_groups()