26 lines
776 B
PHP
26 lines
776 B
PHP
<?php
|
|
|
|
namespace App\Classes;
|
|
|
|
class MusicDataHandler extends BaseHandler
|
|
{
|
|
protected int $cacheTTL = 300;
|
|
|
|
public function getThisWeekData(): array
|
|
{
|
|
$cacheKey = 'music_week_data';
|
|
$cached = $this->cache ? $this->cache->get($cacheKey) : null;
|
|
|
|
if ($cached) return json_decode($cached, true);
|
|
|
|
$response = $this->makeRequest('GET', 'optimized_week_music?select=*');
|
|
$music = $response[0]['week_music'] ?? [];
|
|
$music['total_tracks'] = $music['week_summary']['total_tracks'] ?? 0;
|
|
$music['total_artists'] = $music['week_summary']['total_artists'] ?? 0;
|
|
$music['total_albums'] = $music['week_summary']['total_albums'] ?? 0;
|
|
|
|
if ($this->cache) $this->cache->set($cacheKey, json_encode($music), $this->cacheTTL);
|
|
|
|
return $music;
|
|
}
|
|
}
|