mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
perf: pre-render student popover cards server-side into <template> tags — zero per-hover requests
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user