coryd.dev/app/Classes/BookProgressHandler.php

41 lines
1.1 KiB
PHP

<?php
namespace App\Classes;
class BookProgressHandler extends BaseHandler
{
protected int $cacheTTL = 300;
public function getAllProgress(): array
{
try {
$cacheKey = 'all_books_progress';
if ($this->cache) {
$cached = $this->cache->get($cacheKey);
if ($cached !== false) {
return json_decode($cached, true) ?? [];
}
}
$response = $this->makeRequest('GET', 'optimized_books_progress?select=isbn,progress');
$result = [];
foreach ($response as $row) {
if (!empty($row['isbn'])) {
$result[$row['isbn']] = (int) $row['progress'];
}
}
if ($this->cache) {
$this->cache->set($cacheKey, json_encode($result), $this->cacheTTL);
}
return $result;
} catch (\Throwable $e) {
error_log('BookProgressHandler::getAllProgress error: ' . $e->getMessage());
return [];
}
}
}