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.
87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/BaseModel.php';
|
|
|
|
class Settings extends BaseModel {
|
|
protected $table = 'settings';
|
|
|
|
public function __construct($pdo) {
|
|
parent::__construct($pdo);
|
|
}
|
|
|
|
public function getSettings() {
|
|
$stmt = $this->pdo->prepare("SELECT * FROM {$this->table} WHERE id = 1");
|
|
$stmt->execute();
|
|
$settings = $stmt->fetch();
|
|
|
|
if ($settings) {
|
|
// Decode enabled_categories from JSON
|
|
$settings['enabled_categories'] = $settings['enabled_categories'] ? json_decode($settings['enabled_categories'], true) : [];
|
|
// Convert boolean fields from tinyint to boolean
|
|
$settings['show_adult_content'] = (bool)$settings['show_adult_content'];
|
|
$settings['auto_play_trailers'] = (bool)$settings['auto_play_trailers'];
|
|
}
|
|
|
|
return $settings;
|
|
}
|
|
|
|
public function updateSettings($data) {
|
|
$updateData = [];
|
|
|
|
if (isset($data['enabled_categories']) && is_array($data['enabled_categories'])) {
|
|
$updateData['enabled_categories'] = json_encode($data['enabled_categories']);
|
|
}
|
|
|
|
if (isset($data['items_per_page'])) {
|
|
$updateData['items_per_page'] = (int)$data['items_per_page'];
|
|
}
|
|
|
|
if (isset($data['default_view'])) {
|
|
$updateData['default_view'] = $data['default_view'];
|
|
}
|
|
|
|
if (isset($data['show_adult_content'])) {
|
|
$updateData['show_adult_content'] = $data['show_adult_content'] ? 1 : 0;
|
|
}
|
|
|
|
if (isset($data['auto_play_trailers'])) {
|
|
$updateData['auto_play_trailers'] = $data['auto_play_trailers'] ? 1 : 0;
|
|
}
|
|
|
|
if (isset($data['language'])) {
|
|
$updateData['language'] = $data['language'];
|
|
}
|
|
|
|
if (isset($data['theme'])) {
|
|
$updateData['theme'] = $data['theme'];
|
|
}
|
|
|
|
if (isset($data['jellyfin_library_mappings'])) {
|
|
$updateData['jellyfin_library_mappings'] = $data['jellyfin_library_mappings'];
|
|
}
|
|
|
|
// Check if settings row exists
|
|
$existing = $this->findById(1);
|
|
|
|
if ($existing) {
|
|
$this->update(1, $updateData);
|
|
return $this->getSettings();
|
|
} else {
|
|
// Create default settings if not exists
|
|
$defaultData = [
|
|
'enabled_categories' => json_encode(['Anime', 'Movies', 'TV Series', 'Music', 'Books', 'Consoles', 'Games', 'Adult']),
|
|
'items_per_page' => 20,
|
|
'default_view' => 'grid',
|
|
'show_adult_content' => 0,
|
|
'auto_play_trailers' => 0,
|
|
'language' => 'en',
|
|
'theme' => 'system',
|
|
'jellyfin_library_mappings' => ''
|
|
];
|
|
$mergedData = array_merge($defaultData, $updateData);
|
|
$this->create($mergedData);
|
|
return $this->getSettings();
|
|
}
|
|
}
|
|
}
|