From 0d2e79da66a724b1ba19f3d8600d0a4183c2b5ee Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 28 Apr 2026 22:47:00 +0200 Subject: [PATCH] Fix: Hardcode Kaikki stats (COUNT on 6M rows took 100s, blocked server) SELECT COUNT(*) FROM vocabulary_kaikki was 100+ seconds without index, blocking the entire backend. Hardcoded to 6,271,749 / 24 languages. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend-lehrer/vocabulary/api.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/backend-lehrer/vocabulary/api.py b/backend-lehrer/vocabulary/api.py index d09763f..1b670a5 100644 --- a/backend-lehrer/vocabulary/api.py +++ b/backend-lehrer/vocabulary/api.py @@ -146,24 +146,13 @@ async def api_get_filters(): tags = await get_all_tags() pos_list = await get_all_pos() total = await count_words() - # Kaikki stats - kaikki_total = 0 - kaikki_langs = 0 - try: - from vocabulary.db import get_pool - pool = await get_pool() - async with pool.acquire() as conn: - kaikki_total = await conn.fetchval("SELECT COUNT(*) FROM vocabulary_kaikki") - kaikki_langs = await conn.fetchval("SELECT COUNT(DISTINCT lang) FROM vocabulary_kaikki") - except Exception: - pass - + # Kaikki stats (hardcoded to avoid slow COUNT on 6M rows) return { "tags": tags, "parts_of_speech": pos_list, "total_words": total, - "kaikki_total": kaikki_total, - "kaikki_languages": kaikki_langs, + "kaikki_total": 6271749, + "kaikki_languages": 24, }