Merge remote-tracking branch 'performance_optimize-search-queries/performance/optimize-search-queries' into Develop
Updated Requirements
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user