Rendering code refactor

This commit is contained in:
marc
2025-04-26 19:09:59 +02:00
parent 7a823a98ab
commit d132e6fd60
33 changed files with 638 additions and 188 deletions

View File

@@ -1,3 +1,5 @@
from collections.abc import Iterable
from folkugat_web.dal.sql import Connection, get_connection
from folkugat_web.model import search as search_model
from folkugat_web.model import temes as model
@@ -22,6 +24,21 @@ def get_tema_by_id(tema_id: int, con: Connection | None = None) -> model.Tema |
return conversion.row_to_tema(row) if row else None
def get_temes_by_ids(tema_ids: list[int], con: Connection | None = None) -> list[model.Tema]:
placeholders = ", ".join(["?" for _ in tema_ids])
query = f"""
SELECT
id, title, alternatives, creation_date, modification_date, hidden
FROM temes
WHERE id IN ({placeholders})
"""
with get_connection(con) as con:
cur = con.cursor()
_ = cur.execute(query, tema_ids)
rows: Iterable[conversion.TemaRowTuple] = cur.fetchall()
return list(map(conversion.row_to_tema, rows))
def evict_tema_id_to_ngrams_cache():
global _tema_id_to_ngrams_cache
_tema_id_to_ngrams_cache = None