mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: cover image fallback for home grid cards
- index.php: batch-load thesis_files covers for theses without banner_path - Resolution order: banner_path → cover file → gradient placeholder - Uses single IN() query to avoid N+1 problem
This commit is contained in:
@@ -28,6 +28,26 @@ try {
|
||||
}
|
||||
|
||||
$totalPages = $isDefaultView ? 1 : (int)ceil($totalItems / $itemsPerPage);
|
||||
|
||||
// Batch-load cover images for theses that have no banner_path
|
||||
$coverMap = [];
|
||||
if (!empty($itemsToLoad)) {
|
||||
$needCover = array_column(
|
||||
array_filter($itemsToLoad, fn($t) => empty($t['banner_path'])),
|
||||
'id'
|
||||
);
|
||||
if (!empty($needCover)) {
|
||||
$ph = implode(',', array_fill(0, count($needCover), '?'));
|
||||
$cStmt = $db->getConnection()->prepare("
|
||||
SELECT thesis_id, file_path FROM thesis_files
|
||||
WHERE file_type = 'cover' AND thesis_id IN ($ph)
|
||||
");
|
||||
$cStmt->execute($needCover);
|
||||
foreach ($cStmt->fetchAll() as $row) {
|
||||
$coverMap[$row['thesis_id']] = $row['file_path'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Error loading theses: " . $e->getMessage());
|
||||
$itemsToLoad = [];
|
||||
@@ -36,6 +56,7 @@ try {
|
||||
$totalItems = 0;
|
||||
$latestYear = null;
|
||||
$isDefaultView = false;
|
||||
$coverMap = [];
|
||||
}
|
||||
|
||||
$currentNav = '';
|
||||
@@ -91,7 +112,11 @@ $currentNav = '';
|
||||
$thumb = $item['banner_path'];
|
||||
}
|
||||
|
||||
// 2. Cover image from thesis_files (not returned by view — skip for now)
|
||||
// 2. Cover image from thesis_files (batch-loaded above)
|
||||
if (!$thumb && isset($coverMap[$item['id']])) {
|
||||
$thumb = $coverMap[$item['id']];
|
||||
}
|
||||
|
||||
// 3. Fall through to gradient
|
||||
?>
|
||||
<?php if ($thumb): ?>
|
||||
|
||||
Reference in New Issue
Block a user