Add Jellyfin mappings and optimize cast queries
Performance and settings updates: - Add a new jellyfin_library_mappings column to the settings table and wire it into the Settings model (update handling and default value). This enables storing Jellyfin library mappings in settings. - Optimize Cast::list by loading all cast filmography in a single joined query and grouping results per cast to avoid N+1 queries. - Remove per-item cast/staff loading in Media model to avoid repeated queries during list/search operations. - Remove game-specific enrichment from MediaController search to stop extra game info lookups during search responses. These changes reduce repeated DB calls and centralize Jellyfin mapping storage.
This commit is contained in:
@@ -49,16 +49,37 @@ class Cast extends BaseModel {
|
||||
$items = $this->findAll($conditions, 'createdAt DESC', $limit, $offset);
|
||||
$total = $this->count($conditions);
|
||||
|
||||
|
||||
// Add filmography to each cast member
|
||||
foreach ($items as &$item) {
|
||||
$item['filmography'] = $this->getMediaForCast($item['id']);
|
||||
// Extract unique media types
|
||||
$mediaTypes = array_unique(array_column($item['filmography'], 'category'));
|
||||
$item['media_types'] = array_values($mediaTypes);
|
||||
// Load filmography for all cast members in a single query
|
||||
if (!empty($items)) {
|
||||
$castIds = array_column($items, 'id');
|
||||
$placeholders = str_repeat('?,', count($castIds) - 1) . '?';
|
||||
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT mc.cast_id, m.id, m.title, m.year, m.poster, m.category, m.type, mc.role, mc.characterName
|
||||
FROM media m
|
||||
INNER JOIN media_cast mc ON m.id = mc.media_id
|
||||
WHERE mc.cast_id IN ($placeholders)
|
||||
ORDER BY m.year DESC
|
||||
");
|
||||
$stmt->execute($castIds);
|
||||
$allFilmography = $stmt->fetchAll();
|
||||
|
||||
// Group filmography by cast_id
|
||||
$filmographyByCast = [];
|
||||
foreach ($allFilmography as $film) {
|
||||
$castId = $film['cast_id'];
|
||||
unset($film['cast_id']);
|
||||
$filmographyByCast[$castId][] = $film;
|
||||
}
|
||||
|
||||
// Attach filmography to each cast member
|
||||
foreach ($items as &$item) {
|
||||
$item['filmography'] = $filmographyByCast[$item['id']] ?? [];
|
||||
$mediaTypes = array_unique(array_column($item['filmography'], 'category'));
|
||||
$item['media_types'] = array_values($mediaTypes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'total' => $total,
|
||||
|
||||
Reference in New Issue
Block a user