Skip to content

Commit

Permalink
Revert "Use flexible caching and improve code"
Browse files Browse the repository at this point in the history
This reverts commit 1089e37.
  • Loading branch information
DariusIII committed Sep 13, 2024
1 parent 5d59261 commit 6a5b1fc
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Blacklight/processing/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,33 @@ public function addAliases($videoId, array $aliases = []): void
}
}

/**
* Retrieves all aliases for given VideoID or VideoID for a given alias.
*
*
* @return VideoAlias[]|bool|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|mixed
*/
public function getAliases(int $videoId, string $alias = ''): mixed
{
if ($videoId <= 0 && $alias === '') {
return false;
}

$cacheKey = md5($videoId.$alias);
$return = false;
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));

$sql = VideoAlias::query();
if ($videoId > 0) {
$sql->where('videos_id', $videoId);
} else {
$sql->where('title', $alias);
if ($videoId > 0 || $alias !== '') {
$aliasCache = Cache::get(md5($videoId.$alias));
if ($aliasCache !== null) {
$return = $aliasCache;
} else {
$sql = VideoAlias::query();
if ($videoId > 0) {
$sql->where('videos_id', $videoId);
} elseif ($alias !== '') {
$sql->where('title', $alias);
}
$return = $sql->get();
Cache::put(md5($videoId.$alias), $return, $expiresAt);
}
}

return Cache::flexible($cacheKey, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
$result = $sql->get();

return $result->isEmpty() ? false : $result;
});
return $return->isEmpty() ? false : $return;
}
}

0 comments on commit 6a5b1fc

Please sign in to comment.