mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 10:15:27 -04:00
fix: document library language facet undercounts text documents (#1758)
This commit is contained in:
@@ -15,6 +15,21 @@ from src.auth_helpers import get_current_user
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _aggregate_language_facets(lang_rows):
|
||||
"""Sum document counts per display language for the library facet.
|
||||
|
||||
NULL-language and explicit "text" rows share the "text" bucket (the
|
||||
language filter treats them as one), so they must be ADDED. The old dict
|
||||
comprehension keyed both to "text", silently overwriting one group and
|
||||
undercounting the facet versus what the filter actually returns.
|
||||
"""
|
||||
out = {}
|
||||
for lang, cnt in lang_rows:
|
||||
key = lang or "text"
|
||||
out[key] = out.get(key, 0) + cnt
|
||||
return out
|
||||
|
||||
|
||||
|
||||
from routes.document_helpers import (
|
||||
DocumentCreate, DocumentUpdate, DocumentPatch,
|
||||
@@ -258,7 +273,7 @@ def setup_document_routes(session_manager, upload_handler=None) -> APIRouter:
|
||||
)
|
||||
lang_q = _owner_session_filter(lang_q, user)
|
||||
lang_rows = lang_q.group_by(Document.language).all()
|
||||
languages = {lang or "text": cnt for lang, cnt in lang_rows}
|
||||
languages = _aggregate_language_facets(lang_rows)
|
||||
|
||||
# Session count (owner-filtered)
|
||||
sc_q = (
|
||||
|
||||
Reference in New Issue
Block a user