fix: search_library now correctly returns the number of *unique* entries

This commit is contained in:
Jann Stute
2024-11-28 19:46:45 +01:00
parent d74743565d
commit cdf2f09d60

View File

@@ -18,6 +18,7 @@ from sqlalchemy import (
exists,
func,
or_,
distinct,
select,
update,
)
@@ -474,9 +475,10 @@ class Library:
.options(selectinload(Tag.aliases), selectinload(Tag.subtags)),
)
query_count = select(func.count()).select_from(
statement.alias("entries")
) # TODO this should count the number of *unique* results
aliased_statement = statement.alias("entries")
query_count = select(func.count(distinct(aliased_statement.c.id))).select_from(
aliased_statement
)
count_all: int = session.execute(query_count).scalar()
statement = statement.limit(search.limit).offset(search.offset)