Revert caching to old style

This commit is contained in:
DariusIII
2024-09-13 22:47:21 +02:00
parent 5e592282c2
commit b57731294f
7 changed files with 129 additions and 83 deletions
+13 -12
View File
@@ -102,7 +102,7 @@ class Books
return BookInfo::search($searchWords)->first();
}
public function getBookRange($page, $cat, $start, $num, $orderBy, array $excludedCats = []): mixed
public function getBookRange($page, $cat, $start, $num, $orderBy, array $excludedCats = []): array
{
$browseby = $this->getBrowseBy();
$catsrch = '';
@@ -175,16 +175,17 @@ class Books
$order[0],
$order[1]
);
return Cache::flexible($sql.$page, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql, $books) {
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $books['total'][0]->total ?? 0;
}
$return = Cache::get(md5($sql.$page));
if ($return !== null) {
return $return;
});
}
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $books['total'][0]->total ?? 0;
}
Cache::put(md5($sql.$page), $return, $expiresAt);
return $return;
}
public function getBookOrder($orderBy): array
@@ -474,9 +475,9 @@ class Books
$book['cover'] = $ri->saveImage($bookId, $book['coverurl'], $this->imgSavePath, 250, 250);
} elseif ($this->echooutput) {
$this->colorCli->header('Nothing to update: ').
$this->colorCli->header($book['author'].
' - '.
$book['title']);
$this->colorCli->header($book['author'].
' - '.
$book['title']);
}
return $bookId;
+16 -10
View File
@@ -132,7 +132,10 @@ class Console
return ConsoleInfo::search($searchWords)->first() ?? false;
}
public function getConsoleRange($page, $cat, $start, $num, $orderBy, array $excludedCats = []): mixed
/**
* @throws \Exception
*/
public function getConsoleRange($page, $cat, $start, $num, $orderBy, array $excludedCats = []): array
{
$browseBy = $this->getBrowseBy();
$catsrch = '';
@@ -208,15 +211,18 @@ class Console
$order[0],
$order[1]
);
return Cache::flexible($sql.$page, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql, $consoles) {
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $consoles['total'][0]->total ?? 0;
}
$return = Cache::get(md5($sql.$page));
if ($return !== null) {
return $return;
});
}
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $consoles['total'][0]->total ?? 0;
}
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
Cache::put(md5($sql.$page), $return, $expiresAt);
return $return;
}
public function getConsoleOrder($orderBy): array
@@ -759,7 +765,7 @@ class Console
} else {
if ($this->echooutput) {
$this->colorCli->headerOver('Found Local: ').
$this->colorCli->primary("{$gameInfo['title']} - {$gameInfo['platform']}");
$this->colorCli->primary("{$gameInfo['title']} - {$gameInfo['platform']}");
}
$gameId = $gameCheck['id'] ?? -2;
}
+19 -14
View File
@@ -163,7 +163,10 @@ class Games
return $res ?? 0;
}
public function getGamesRange($page, $cat, $start, $num, array|string $orderBy = '', string $maxAge = '', array $excludedCats = []): mixed
/**
* @throws \Exception
*/
public function getGamesRange($page, $cat, $start, $num, array|string $orderBy = '', string $maxAge = '', array $excludedCats = []): array
{
$browseBy = $this->getBrowseBy();
$catsrch = '';
@@ -240,15 +243,17 @@ class Games
$order[0],
$order[1]
);
return Cache::flexible($returnSql.$page, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($returnSql, $games) {
$return = DB::select($returnSql);
if (\count($return) > 0) {
$return[0]->_totalcount = $games['total'][0]->total ?? 0;
}
$return = Cache::get(md5($returnSql.$page));
if ($return !== null) {
return $return;
});
}
$return = DB::select($returnSql);
if (\count($return) > 0) {
$return[0]->_totalcount = $games['total'][0]->total ?? 0;
}
Cache::put(md5($returnSql.$page), $return, $expiresAt);
return $return;
}
public function getGamesOrder(array|string $orderBy): array
@@ -639,10 +644,10 @@ class Games
if (! empty($gamesId)) {
if ($this->echoOutput) {
$this->colorCli->header('Added/updated game: ').
$this->colorCli->alternateOver(' Title: ').
$this->colorCli->primary($game['title']).
$this->colorCli->alternateOver(' Source: ').
$this->colorCli->primary($this->_classUsed);
$this->colorCli->alternateOver(' Title: ').
$this->colorCli->primary($game['title']).
$this->colorCli->alternateOver(' Source: ').
$this->colorCli->primary($this->_classUsed);
}
if ($game['cover'] === 1) {
$game['cover'] = $ri->saveImage($gamesId, $game['coverurl'], $this->imgSavePath, 250, 250);
@@ -652,7 +657,7 @@ class Games
}
} elseif ($this->echoOutput) {
$this->colorCli->headerOver('Nothing to update: ').
$this->colorCli->primary($game['title'].' (PC)');
$this->colorCli->primary($game['title'].' (PC)');
}
return ! empty($gamesId) ? $gamesId : false;
+22 -7
View File
@@ -25,13 +25,21 @@ class Genres
public function __construct() {}
public function getGenres(string $type = '', bool $activeOnly = false): mixed
/**
* @return array|mixed
*/
public function getGenres(string $type = '', bool $activeOnly = false)
{
$sql = $this->getListQuery($type, $activeOnly);
$genres = Cache::get(md5($sql));
if ($genres !== null) {
return $genres;
}
$genres = DB::select($sql);
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
Cache::put(md5($sql), $genres, $expiresAt);
return Cache::flexible($sql, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
return DB::select($sql);
});
return $genres;
}
public function loadGenres($type): array
@@ -148,8 +156,15 @@ class Genres
*/
public function getDisabledIDs()
{
return Cache::flexible('disabledCats', [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () {
return Genre::query()->where('disabled', '=', 1)->get(['id']);
});
$cats = Cache::get('disabledcats');
if ($cats !== null) {
$disabled = $cats;
} else {
$disabled = Genre::query()->where('disabled', '=', 1)->get(['id']);
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
Cache::put('disabledcats', $disabled, $expiresAt);
}
return $disabled;
}
}
+34 -19
View File
@@ -16,6 +16,8 @@ use DariusIII\ItunesApi\Exceptions\SearchNoResultsException;
use DariusIII\ItunesApi\iTunes;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
@@ -82,7 +84,10 @@ class Movie
*/
public mixed $omdbapikey;
public bool $imdburl;
/**
* @var bool
*/
public $imdburl;
public int $movieqty;
@@ -146,12 +151,21 @@ class Movie
$this->service = '';
}
/**
* @return Builder|Model|null|object
*/
public function getMovieInfo($imdbId)
{
return MovieInfo::query()->where('imdbid', $imdbId)->first();
}
public function getMovieRange($page, $cat, $start, $num, $orderBy, int $maxAge = -1, array $excludedCats = []): mixed
/**
* Get movie releases with covers for movie browse page.
*
*
* @return array|mixed
*/
public function getMovieRange($page, $cat, $start, $num, $orderBy, int $maxAge = -1, array $excludedCats = [])
{
$catsrch = '';
if (\count($cat) > 0 && $cat[0] !== -1) {
@@ -179,8 +193,8 @@ class Movie
(! empty($catsrch) ? $catsrch : ''),
(
$maxAge > 0
? 'AND r.postdate > NOW() - INTERVAL '.$maxAge.'DAY '
: ''
? 'AND r.postdate > NOW() - INTERVAL '.$maxAge.'DAY '
: ''
),
\count($excludedCats) > 0 ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : '',
$order[0],
@@ -241,16 +255,17 @@ class Movie
$order[0],
$order[1]
);
return Cache::flexible(md5($sql.$page), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql, $movies) {
$return = Release::fromQuery($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $movies['total'][0]->total ?? 0;
}
$return = Cache::get(md5($sql.$page));
if ($return !== null) {
return $return;
});
}
$return = Release::fromQuery($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $movies['total'][0]->total ?? 0;
}
Cache::put(md5($sql.$page), $return, $expiresAt);
return $return;
}
/**
@@ -598,13 +613,13 @@ class Movie
if ($this->echooutput && $this->service !== '') {
PHP_EOL.$this->colorCli->headerOver('Added/updated movie: ').
$this->colorCli->primary(
$mov['title'].
' ('.
$mov['year'].
') - '.
$mov['imdbid']
);
$this->colorCli->primary(
$mov['title'].
' ('.
$mov['year'].
') - '.
$mov['imdbid']
);
}
return $movieID;
+15 -13
View File
@@ -201,15 +201,17 @@ class Music
$order[0],
$order[1]
);
return Cache::flexible($sql.$page, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql, $music) {
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $music['total'][0]->total ?? 0;
}
$return = Cache::get(md5($sql.$page));
if ($return !== null) {
return $return;
});
}
$return = MusicInfo::fromQuery($sql);
if ($return->isNotEmpty()) {
$return[0]->_totalcount = $music['total'][0]->total ?? 0;
}
Cache::put(md5($sql.$page), $return, $expiresAt);
return $return;
}
public function getMusicOrder($orderBy): array
@@ -375,11 +377,11 @@ class Music
$this->colorCli->headerOver(
'Nothing to update: '.
$artist.
$mus['title'].
' ('.
$year.
')'
$artist.
$mus['title'].
' ('.
$year.
')'
);
}
+10 -8
View File
@@ -166,15 +166,17 @@ class XXX
$order[0],
$order[1]
);
return Cache::flexible($sql.$page, [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql, $xxxmovies) {
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $xxxmovies['total'][0]->total ?? 0;
}
$return = Cache::get(md5($sql.$page));
if ($return !== null) {
return $return;
});
}
$return = DB::select($sql);
if (\count($return) > 0) {
$return[0]->_totalcount = $xxxmovies['total'][0]->total ?? 0;
}
Cache::put(md5($sql.$page), $return, $expiresAt);
return $return;
}
/**