feat(reading/index.php.liquid): update reading progress on page load
This commit is contained in:
parent
320f5e53db
commit
fc32f457c0
7 changed files with 75 additions and 9 deletions
41
app/Classes/BookProgressHandler.php
Normal file
41
app/Classes/BookProgressHandler.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?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 [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue