Оптимизация вычитки листов из кэша с пагинацией, удалены количества онлайн/офлайн листов
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user