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:
@@ -146,24 +146,13 @@ async def api_get_filters():
|
|||||||
tags = await get_all_tags()
|
tags = await get_all_tags()
|
||||||
pos_list = await get_all_pos()
|
pos_list = await get_all_pos()
|
||||||
total = await count_words()
|
total = await count_words()
|
||||||
# Kaikki stats
|
# Kaikki stats (hardcoded to avoid slow COUNT on 6M rows)
|
||||||
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
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
"parts_of_speech": pos_list,
|
"parts_of_speech": pos_list,
|
||||||
"total_words": total,
|
"total_words": total,
|
||||||
"kaikki_total": kaikki_total,
|
"kaikki_total": 6271749,
|
||||||
"kaikki_languages": kaikki_langs,
|
"kaikki_languages": 24,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user