Оптимизация вычитки листов из кэша с пагинацией, удалены количества онлайн/офлайн листов

This commit is contained in:
2025-10-22 00:59:56 +08:00
parent 71304f6d84
commit 993625aa8f
3 changed files with 18 additions and 24 deletions

View File

@@ -30,13 +30,15 @@ class IniFile
/**
* Считывает ini-файл и инициализирует плейлисты
*
* @return void
* @return array
*/
public function load(): void
public function load(): array
{
$filepath = config_path('playlists.ini');
$this->playlists = parse_ini_file($filepath, true);
$this->updatedAt = date('d.m.Y h:i', filemtime($filepath));
return $this->playlists;
}
/**
@@ -45,16 +47,17 @@ class IniFile
* @return array[]
* @throws Exception
*/
public function getPlaylists(): array
public function getPlaylists(array $plsCodes = []): array
{
$playlists = [];
empty($this->playlists) && $this->load();
$plsCodes = array_keys($this->playlists);
empty($plsCodes) && $plsCodes = array_keys($this->playlists);
$cached = array_combine($plsCodes, redis()->mget($plsCodes));
foreach ($cached as $code => $data) {
$this->playlists[$code] = $this->initPlaylist($code, $data);
$playlists[$code] = $this->initPlaylist($code, $data);
}
return $this->playlists;
return $playlists;
}
/**
@@ -69,9 +72,7 @@ class IniFile
{
empty($this->playlists) && $this->load();
$data = redis()->get($code);
$pls = $this->initPlaylist($code, $data);
return $pls ?? throw new PlaylistNotFoundException($code);
return $this->initPlaylist($code, $data);
}
/**
@@ -90,11 +91,13 @@ class IniFile
* @param string $code
* @param array|false $data
* @return array
* @throws PlaylistNotFoundException
*/
protected function initPlaylist(string $code, array|false $data): array
{
if ($data === false) {
$raw = $this->playlists[$code];
empty($raw) && throw new PlaylistNotFoundException($code);
$data === false && $data = [
'code' => $code,
'name' => $raw['name'] ?? "Плейлист #$code",