perf: pre-render student popover cards server-side into <template> tags — zero per-hover requests

This commit is contained in:
Pontoporeia
2026-04-24 13:17:47 +02:00
parent 53c3127140
commit e590d8e035
5 changed files with 101 additions and 30 deletions

View File

@@ -473,6 +473,37 @@ class Database {
return $stmt->fetchAll();
}
/**
* Batch variant: fetch preview data for a list of author names in one query.
* Returns [ authorName => [ thesis, ... ], ... ]
*
* @param string[] $names
* @return array<string, array>
*/
public function getThesesForAuthors(array $names): array {
if (empty($names)) return [];
$placeholders = implode(',', array_fill(0, count($names), '?'));
$stmt = $this->pdo->prepare(
"SELECT a.name AS author_name,
vp.id, vp.title, vp.subtitle, vp.year, vp.synopsis,
vp.orientation, vp.finality_type, vp.banner_path, vp.authors
FROM v_theses_public vp
JOIN thesis_authors ta ON ta.thesis_id = vp.id
JOIN authors a ON a.id = ta.author_id
WHERE a.name IN ($placeholders)
ORDER BY a.name ASC, vp.year DESC, vp.title ASC"
);
$stmt->execute($names);
$rows = $stmt->fetchAll();
$grouped = [];
foreach ($rows as $row) {
$grouped[$row['author_name']][] = $row;
}
return $grouped;
}
public function getAvailableYears() {
$sql = "SELECT DISTINCT year FROM theses WHERE is_published = 1 ORDER BY year DESC";
$stmt = $this->pdo->query($sql);