From fceca5cc0869956b35d30d380f0f28a3a3ba76be Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Fri, 5 Dec 2025 16:34:14 +0100 Subject: [PATCH] Merge remote-tracking branch 'performance_optimize-search-queries/performance/optimize-search-queries' into Develop Updated Requirements --- cps/db.py | 5 +- cps/editbooks.py | 2 +- cps/helper.py | 4 +- requirements.txt | 2 +- test/Calibre-Web TestSummary_Linux.html | 2204 ++++------------------- 5 files changed, 333 insertions(+), 1884 deletions(-) diff --git a/cps/db.py b/cps/db.py index bb460c6ca..49fdfcc77 100644 --- a/cps/db.py +++ b/cps/db.py @@ -999,7 +999,6 @@ class CalibreDB: # Apply eager loading for authors to avoid N+1 queries base_query = base_query.options(selectinload(Books.authors)) - if len(join) == 6: base_query = base_query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]).outerjoin(join[5]) @@ -1015,7 +1014,7 @@ class CalibreDB: return base_query.filter(Books.id.in_(fts_ids)) # Fallback to traditional search with optimized subqueries - q = list() + # q = list() author_terms = re.split("[, ]+", term) # Use subquery for authors to avoid expensive .any() with OR @@ -1026,7 +1025,7 @@ class CalibreDB: for author_term in author_terms: author_filters.append(func.lower(Authors.name).ilike("%" + author_term + "%")) if author_filters: - author_subquery = author_subquery.filter(or_(*author_filters)) + author_subquery = author_subquery.filter(and_(*author_filters)) # Build optimized filter expressions cc = self.get_cc_columns(config, filter_config_custom_read=True) diff --git a/cps/editbooks.py b/cps/editbooks.py index a2c39b9d9..1999e7564 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -406,7 +406,7 @@ def edit_book_param(param, vals, multi=False): kobo_sync_status.remove_synced_book(book.id) continue elif param == 'read_status': - error = helper.edit_book_read_status(book.id, vals['value'] == "True") + error = helper.edit_book_read_status(book.id, vals['value'] == "True", True) if error: if multi: out.append({"success":False, "msg":error}) diff --git a/cps/helper.py b/cps/helper.py index dd6298826..28edb9f32 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -303,7 +303,7 @@ def get_sorted_author(value): return value2 -def edit_book_read_status(book_id, read_status=None): +def edit_book_read_status(book_id, read_status=None, archived=False): if not config.config_read_column: book = ub.session.query(ub.ReadBook).filter(and_(ub.ReadBook.user_id == int(current_user.id), ub.ReadBook.book_id == book_id)).first() @@ -327,7 +327,7 @@ def edit_book_read_status(book_id, read_status=None): else: try: calibre_db.create_functions(config) - book = calibre_db.get_filtered_book(book_id) + book = calibre_db.get_filtered_book(book_id, archived) book_read_status = getattr(book, 'custom_column_' + str(config.config_read_column)) if len(book_read_status): if read_status is None: diff --git a/requirements.txt b/requirements.txt index 44f016cd8..9c858ede5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ Flask-Principal>=0.3.2,<0.5.1 Flask>=1.0.2,<3.2.0 iso-639>=0.4.5,<0.5.0;python_version<'3.12' pycountry>=20.0.0,<25.0.0;python_version>='3.12' -PyPDF>=3.15.6,<5.5.0 +PyPDF>=6.1.3,<6.5.0 pytz>=2016.10 requests>=2.32.0,<2.33.0 SQLAlchemy>=1.3.0,<2.1.0 diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 9fa8449f8..f66af93cb 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2025-12-04 20:11:40

+

Start Time: 2025-12-05 16:37:33

-

Stop Time: 2025-12-05 03:15:12

+

Stop Time: 2025-12-05 23:59:26

-

Duration: 5h 48 min

+

Duration: 6h 5 min

@@ -1023,12 +1023,12 @@ - + TestEditAdditionalBooks 18 - 12 - 1 - 5 + 18 + 0 + 0 0 Detail @@ -1118,231 +1118,56 @@ - +
TestEditAdditionalBooks - test_title_sort
- -
- FAIL -
- - - - + PASS - +
TestEditAdditionalBooks - test_upload_cbz_coverformats
- -
- ERROR -
- - - - + PASS - +
TestEditAdditionalBooks - test_upload_edit_role
- -
- ERROR -
- - - - + PASS - +
TestEditAdditionalBooks - test_upload_metadata_cb7
- -
- ERROR -
- - - - + PASS - +
TestEditAdditionalBooks - test_upload_metadata_cbr
- -
- ERROR -
- - - - + PASS - +
TestEditAdditionalBooks - test_upload_metadata_cbt
- -
- ERROR -
- - - - + PASS @@ -1375,12 +1200,12 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - + TestEditBooks 38 - 29 - 1 - 7 + 34 + 3 + 0 1 Detail @@ -1451,9 +1276,9 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16
Traceback (most recent call last):
-  File "/home/ozzie/Development/calibre-web-test/test/test_edit_books.py", line 619, in test_edit_custom_categories
-    self.assertEqual(len(self.search(u'人 Ü')), 1)
-AssertionError: 0 != 1
+ File "/home/ozzie/Development/calibre-web-test/test/test_edit_books.py", line 610, in test_edit_custom_categories + self.assertEqual(len(self.search(u'人 Ü')), 0) +AssertionError: 4 != 0
@@ -1463,27 +1288,26 @@ AssertionError: 0 != 1 - +
TestEditBooks - test_edit_custom_comment
- ERROR + FAIL
-