Revert "Revert "Use flexible cache""

This reverts commit b145500ac4.
This commit is contained in:
DariusIII
2024-09-13 22:11:16 +02:00
parent e5782ae554
commit 72e57c0419
3 changed files with 56 additions and 137 deletions
+12 -45
View File
@@ -8,8 +8,6 @@ use App\Models\UserMovie;
use App\Models\UserSerie;
use Blacklight\NZB;
use Blacklight\Releases;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
@@ -30,10 +28,7 @@ class RSS extends ApiController
$this->releases = new Releases;
}
/**
* @return Release[]|Collection|mixed
*/
public function getRss($cat, $videosId, $aniDbID, int $userID = 0, int $airDate = -1, int $limit = 100, int $offset = 0)
public function getRss($cat, $videosId, $aniDbID, int $userID = 0, int $airDate = -1, int $limit = 100, int $offset = 0): mixed
{
$catSearch = $cartSearch = '';
$catLimit = 'AND r.categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER;
@@ -86,22 +81,12 @@ class RSS extends ApiController
$limit === -1 ? '' : ' LIMIT '.$limit.' OFFSET '.$offset
);
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
$result = Cache::get(md5($sql));
if ($result !== null) {
return $result;
}
$result = Release::fromQuery($sql);
Cache::put(md5($sql), $result, $expiresAt);
return $result;
return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
return Release::fromQuery($sql);
});
}
/**
* @return Builder|Collection
*/
public function getShowsRss(int $limit, int $userID = 0, array $excludedCats = [], int $airDate = -1)
public function getShowsRss(int $limit, int $userID = 0, array $excludedCats = [], int $airDate = -1): mixed
{
$sql = sprintf(
"
@@ -140,22 +125,12 @@ class RSS extends ApiController
! empty($limit) ? sprintf(' LIMIT %d OFFSET 0', $limit > 100 ? 100 : $limit) : ''
);
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
$result = Cache::get(md5($sql));
if ($result !== null) {
return $result;
}
$result = Release::fromQuery($sql);
Cache::put(md5($sql), $result, $expiresAt);
return $result;
return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
return Release::fromQuery($sql);
});
}
/**
* @return Release[]|Collection|mixed
*/
public function getMyMoviesRss(int $limit, int $userID = 0, array $excludedCats = [])
public function getMyMoviesRss(int $limit, int $userID = 0, array $excludedCats = []): mixed
{
$sql = sprintf(
"
@@ -192,17 +167,9 @@ class RSS extends ApiController
! empty($limit) ? sprintf(' LIMIT %d OFFSET 0', $limit > 100 ? 100 : $limit) : ''
);
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
$result = Cache::get(md5($sql));
if ($result !== null) {
return $result;
}
$result = Release::fromQuery($sql);
Cache::put(md5($sql), $result, $expiresAt);
return $result;
return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
return Release::fromQuery($sql);
});
}
/**