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

@@ -49,6 +49,7 @@ def get_playlist_entries(
id, session_id, set_id, tema_id
FROM playlists
WHERE {filter_clause}
ORDER BY id ASC
"""
with get_connection(con) as con:
cur = con.cursor()

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

View File

@@ -3,8 +3,8 @@ from collections.abc import Iterable
from typing import TypedDict
from folkugat_web.dal.sql import Connection, get_connection
from folkugat_web.model import lilypond as lilypond_model
from folkugat_web.model import temes as model
from folkugat_web.model.lilypond.processing import RenderError
ScoreRowTuple = tuple[int, int, str, str, str, str | None, str | None, bool]
@@ -40,7 +40,7 @@ def row_to_score(row: ScoreRowTuple) -> model.Score:
tema_id=row[1],
title=row[2],
source=row[3],
errors=list(map(lilypond_model.RenderError.from_dict, errors_dicts)),
errors=list(map(RenderError.from_dict, errors_dicts)),
img_url=row[5],
pdf_url=row[6],
hidden=bool(row[7]),