From 30af514681949779c3f33db9f4ed6c54a57d9882 Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Thu, 2 Jan 2025 01:49:22 +0100 Subject: [PATCH] feat: reduce time consumption of counting total results massively --- tagstudio/src/core/library/alchemy/library.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/core/library/alchemy/library.py b/tagstudio/src/core/library/alchemy/library.py index 845ae3a8..6837c616 100644 --- a/tagstudio/src/core/library/alchemy/library.py +++ b/tagstudio/src/core/library/alchemy/library.py @@ -573,7 +573,9 @@ class Library: statement = statement.distinct(Entry.id) - query_count = select(func.count()).select_from(statement.alias("entries")) + # only selecting the id and counting on that is quicker when using the ORM + counting_statement = select(statement.alias("result").c[0]) + query_count = select(func.count()).select_from(counting_statement.alias("entries")) count_all: int = session.execute(query_count).scalar() statement = statement.limit(search.limit).offset(search.offset)