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
|
# Apply eager loading for authors to avoid N+1 queries
|
||||||
base_query = base_query.options(selectinload(Books.authors))
|
base_query = base_query.options(selectinload(Books.authors))
|
||||||
|
|
||||||
|
|
||||||
if len(join) == 6:
|
if len(join) == 6:
|
||||||
base_query = base_query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]).outerjoin(join[5])
|
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))
|
return base_query.filter(Books.id.in_(fts_ids))
|
||||||
|
|
||||||
# Fallback to traditional search with optimized subqueries
|
# Fallback to traditional search with optimized subqueries
|
||||||
q = list()
|
# q = list()
|
||||||
author_terms = re.split("[, ]+", term)
|
author_terms = re.split("[, ]+", term)
|
||||||
|
|
||||||
# Use subquery for authors to avoid expensive .any() with OR
|
# Use subquery for authors to avoid expensive .any() with OR
|
||||||
@@ -1026,7 +1025,7 @@ class CalibreDB:
|
|||||||
for author_term in author_terms:
|
for author_term in author_terms:
|
||||||
author_filters.append(func.lower(Authors.name).ilike("%" + author_term + "%"))
|
author_filters.append(func.lower(Authors.name).ilike("%" + author_term + "%"))
|
||||||
if author_filters:
|
if author_filters:
|
||||||
author_subquery = author_subquery.filter(or_(*author_filters))
|
author_subquery = author_subquery.filter(and_(*author_filters))
|
||||||
|
|
||||||
# Build optimized filter expressions
|
# Build optimized filter expressions
|
||||||
cc = self.get_cc_columns(config, filter_config_custom_read=True)
|
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)
|
kobo_sync_status.remove_synced_book(book.id)
|
||||||
continue
|
continue
|
||||||
elif param == 'read_status':
|
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 error:
|
||||||
if multi:
|
if multi:
|
||||||
out.append({"success":False, "msg":error})
|
out.append({"success":False, "msg":error})
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ def get_sorted_author(value):
|
|||||||
return value2
|
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:
|
if not config.config_read_column:
|
||||||
book = ub.session.query(ub.ReadBook).filter(and_(ub.ReadBook.user_id == int(current_user.id),
|
book = ub.session.query(ub.ReadBook).filter(and_(ub.ReadBook.user_id == int(current_user.id),
|
||||||
ub.ReadBook.book_id == book_id)).first()
|
ub.ReadBook.book_id == book_id)).first()
|
||||||
@@ -327,7 +327,7 @@ def edit_book_read_status(book_id, read_status=None):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
calibre_db.create_functions(config)
|
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))
|
book_read_status = getattr(book, 'custom_column_' + str(config.config_read_column))
|
||||||
if len(book_read_status):
|
if len(book_read_status):
|
||||||
if read_status is None:
|
if read_status is None:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Flask-Principal>=0.3.2,<0.5.1
|
|||||||
Flask>=1.0.2,<3.2.0
|
Flask>=1.0.2,<3.2.0
|
||||||
iso-639>=0.4.5,<0.5.0;python_version<'3.12'
|
iso-639>=0.4.5,<0.5.0;python_version<'3.12'
|
||||||
pycountry>=20.0.0,<25.0.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
|
pytz>=2016.10
|
||||||
requests>=2.32.0,<2.33.0
|
requests>=2.32.0,<2.33.0
|
||||||
SQLAlchemy>=1.3.0,<2.1.0
|
SQLAlchemy>=1.3.0,<2.1.0
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user