update: use cache()->flexible() to improve response times

This commit is contained in:
Roardom
2025-09-12 01:00:35 +00:00
parent 78ff837e83
commit 2a3270e748
20 changed files with 135 additions and 135 deletions
@@ -109,7 +109,7 @@ class QuickSearchController extends Controller
$searchQuery = fn () => $client->multiSearch($searchQueries, ((new MultiSearchFederation()))->setLimit(20));
if (preg_match("/^[a-zA-Z0-9-_ .'@:\\[\\]+&\\/,!#()?\"]{1,2}$/", $query)) {
$multiSearchResults = cache()->remember('quick-search:'.strtolower($query), 3600 * 24, $searchQuery);
$multiSearchResults = cache()->flexible('quick-search:'.strtolower($query), [3600 * 24, 3600 * 24 * 2], $searchQuery);
} else {
$multiSearchResults = $searchQuery();
}
@@ -70,7 +70,7 @@ class TorrentController extends BaseController
*/
public function index(): TorrentsResource
{
$torrents = cache()->remember('torrent-api-index', 300, function () {
$torrents = cache()->flexible('torrent-api-index', [60 * 5, 60 * 6], function () {
$torrents = Torrent::with(
['user:id,username', 'category', 'type', 'resolution', 'region', 'distributor', 'files']
)
@@ -567,7 +567,7 @@ class TorrentController extends BaseController
$cacheKey = $url.'?'.$queryString;
/** @phpstan-ignore method.unresolvableReturnType (phpstan is unable to resolve type because it's returning a phpstan-ignored line) */
[$torrents, $hasMore] = cache()->remember($cacheKey, 300, function () use ($request, $isSqlAllowed) {
[$torrents, $hasMore] = cache()->flexible($cacheKey, [60 * 5, 60 * 6], function () use ($request, $isSqlAllowed) {
$eagerLoads = fn (Builder $query) => $query
->with(['user:id,username', 'category', 'type', 'resolution', 'distributor', 'region', 'files'])
->select('*')