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) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-04-28 22:47:00 +02:00
parent cb4ea8e49a
commit 0d2e79da66

View File

@@ -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,
}