From 4b4bc72b4bb5cb1c3faa20ccbdf1a5c164bfdb5d Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 9 May 2018 23:15:00 +0200 Subject: [PATCH] Rearrange pagination queries --- Blacklight/AniDB.php | 16 ++--- Blacklight/Books.php | 38 +++++----- Blacklight/Console.php | 2 +- Blacklight/Games.php | 40 ++++++----- Blacklight/Movie.php | 32 ++++----- Blacklight/Music.php | 38 +++++----- Blacklight/Regexes.php | 2 +- Blacklight/Releases.php | 128 +++++++++++++++------------------ Blacklight/XXX.php | 31 ++++---- Blacklight/utility/Utility.php | 2 +- Changelog | 1 + 11 files changed, 160 insertions(+), 170 deletions(-) diff --git a/Blacklight/AniDB.php b/Blacklight/AniDB.php index d4f61b749..0498ab26e 100755 --- a/Blacklight/AniDB.php +++ b/Blacklight/AniDB.php @@ -144,26 +144,24 @@ class AniDB * Retrieves a range of Anime titles for site display. * * - * @param $page * @param string $animetitle * * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ - public function getAnimeRange($page, $animetitle = '') + public function getAnimeRange($animetitle = '') { $query = AnidbTitle::query() - ->select(['at.anidbid', DB::raw("GROUP_CONCAT(at.title SEPARATOR ', ') AS title"), 'ai.description']) - ->from('anidb_titles as at') - ->leftJoin('anidb_info as ai', 'ai.anidbid', '=', 'at.anidbid') ->where('at.lang', '=', 'en'); if ($animetitle !== '') { $query->where('at.title', 'LIKE', '%'.$animetitle.'%'); } + $query->select(['at.anidbid', DB::raw("GROUP_CONCAT(at.title SEPARATOR ', ') AS title"), 'ai.description']) + ->from('anidb_titles as at') + ->leftJoin('anidb_info as ai', 'ai.anidbid', '=', 'at.anidbid') + ->groupBy('at.anidbid') + ->orderByDesc('at.anidbid'); - $query->groupBy('at.anidbid') - ->orderByDesc('at.anidbid'); - - return $query->simplePaginate(config('nntmux.items_per_page')); + return $query->paginate(config('nntmux.items_per_page')); } /** diff --git a/Blacklight/Books.php b/Blacklight/Books.php index 72069dce0..049cd63bf 100755 --- a/Blacklight/Books.php +++ b/Blacklight/Books.php @@ -152,7 +152,18 @@ class Books $order = $this->getBookOrder($orderBy); $sql = Release::query() - ->select( + ->where('r.nzbstatus', '=', 1) + ->where('b.title', '!=', '') + ->where('b.cover', '=', 1); + Releases::showPasswords($sql, true); + if (\count($excludedCats) > 0) { + $sql->whereNotIn('r.categories_id', $excludedCats); + } + + if (\count($cat) > 0 && $cat[0] !== -1) { + Category::getCategorySearch($cat, $sql, true); + } + $sql->select( [ 'b.*', 'r.bookinfo_id', @@ -179,19 +190,7 @@ class Books ->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id') ->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id') ->join('bookinfo as b', 'b.id', '=', 'r.bookinfo_id') - ->where('r.nzbstatus', '=', 1) - ->where('b.title', '!=', '') - ->where('b.cover', '=', 1); - Releases::showPasswords($sql, true); - if (\count($excludedCats) > 0) { - $sql->whereNotIn('r.categories_id', $excludedCats); - } - - if (\count($cat) > 0 && $cat[0] !== -1) { - Category::getCategorySearch($cat, $sql, true); - } - - $sql->groupBy('b.id') + ->groupBy('b.id') ->orderBy($order[0], $order[1]); $return = Cache::get(md5($page.implode('.', $cat).implode('.', $order).implode('.', $excludedCats))); @@ -199,7 +198,7 @@ class Books return $return; } - $return = $sql->simplePaginate(config('nntmux.items_per_cover_page')); + $return = $sql->paginate(config('nntmux.items_per_cover_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long')); Cache::put(md5($page.implode('.', $cat).implode('.', $order).implode('.', $excludedCats)), $return, $expiresAt); @@ -464,7 +463,8 @@ class Books if (preg_match('/^([a-z0-9] )+$|ArtofUsenet|ekiosk|(ebook|mobi).+collection|erotica|Full Video|ImwithJamie|linkoff org|Mega.+pack|^[a-z0-9]+ (?!((January|February|March|April|May|June|July|August|September|O(c|k)tober|November|De(c|z)ember)))[a-z]+( (ebooks?|The))?$|NY Times|(Book|Massive) Dump|Sexual/i', $releasename)) { if ($this->echooutput) { ColorCLI::doEcho( - ColorCLI::headerOver('Changing category to misc books: ').ColorCLI::primary($releasename), true + ColorCLI::headerOver('Changing category to misc books: ').ColorCLI::primary($releasename), + true ); } Release::query()->where('id', $releaseID)->update(['categories_id' => Category::BOOKS_UNKNOWN]); @@ -475,7 +475,8 @@ class Books if (preg_match('/^([a-z0-9ΓΌ!]+ ){1,2}(N|Vol)?\d{1,4}(a|b|c)?$|^([a-z0-9]+ ){1,2}(Jan( |unar|$)|Feb( |ruary|$)|Mar( |ch|$)|Apr( |il|$)|May(?![a-z0-9])|Jun( |e|$)|Jul( |y|$)|Aug( |ust|$)|Sep( |tember|$)|O(c|k)t( |ober|$)|Nov( |ember|$)|De(c|z)( |ember|$))/ui', $releasename) && ! preg_match('/Part \d+/i', $releasename)) { if ($this->echooutput) { ColorCLI::doEcho( - ColorCLI::headerOver('Changing category to magazines: ').ColorCLI::primary($releasename), true + ColorCLI::headerOver('Changing category to magazines: ').ColorCLI::primary($releasename), + true ); } Release::query()->where('id', $releaseID)->update(['categories_id' => Category::BOOKS_MAGAZINES]); @@ -651,7 +652,8 @@ class Books ColorCLI::header('Nothing to update: '). ColorCLI::header($book['author']. ' - '. - $book['title']), true + $book['title']), + true ); } } diff --git a/Blacklight/Console.php b/Blacklight/Console.php index 3214ef4f0..af37a7830 100755 --- a/Blacklight/Console.php +++ b/Blacklight/Console.php @@ -200,7 +200,7 @@ class Console return $return; } - $return = $sql->simplePaginate(config('nntmux.items_per_cover_page')); + $return = $sql->paginate(config('nntmux.items_per_cover_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long')); Cache::put(md5($page.implode('.', $cat).implode('.', $excludedcats)), $return, $expiresAt); diff --git a/Blacklight/Games.php b/Blacklight/Games.php index 3665d6fb7..7d426f57b 100755 --- a/Blacklight/Games.php +++ b/Blacklight/Games.php @@ -194,7 +194,7 @@ class Games ->from('gamesinfo as gi') ->join('genres as g', 'gi.genres_id', '=', 'g.id') ->orderByDesc('created_at') - ->simplePaginate(config('nntmux.items_per_page')); + ->paginate(config('nntmux.items_per_page')); } /** @@ -218,7 +218,18 @@ class Games public function getGamesRange($page, $cat, array $excludedcats = []) { $sql = Release::query() - ->select( + ->where('r.nzbstatus', '=', 1) + ->where('gi.title', '!=', '') + ->where('gi.cover', '=', 1); + Releases::showPasswords($sql, true); + if (\count($excludedcats) > 0) { + $sql->whereNotIn('r.categories_id', $excludedcats); + } + + if (\count($cat) > 0 && $cat[0] !== -1) { + Category::getCategorySearch($cat, $sql, true); + } + $sql->select( [ 'gi.*', 'r.gamesinfo_id', @@ -247,19 +258,7 @@ class Games ->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id') ->join('gamesinfo as gi', 'gi.id', '=', 'r.gamesinfo_id') ->join('genres as gn', 'gi.genres_id', '=', 'gn.id') - ->where('r.nzbstatus', '=', 1) - ->where('gi.title', '!=', '') - ->where('gi.cover', '=', 1); - Releases::showPasswords($sql, true); - if (\count($excludedcats) > 0) { - $sql->whereNotIn('r.categories_id', $excludedcats); - } - - if (\count($cat) > 0 && $cat[0] !== -1) { - Category::getCategorySearch($cat, $sql, true); - } - - $sql->groupBy('gi.id') + ->groupBy('gi.id') ->orderBy('r.postdate', 'desc'); $return = Cache::get(md5($page.implode('.', $cat).implode('.', $excludedcats))); @@ -267,7 +266,7 @@ class Games return $return; } - $return = $sql->simplePaginate(config('nntmux.items_per_cover_page')); + $return = $sql->paginate(config('nntmux.items_per_cover_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long')); Cache::put(md5($page.implode('.', $cat).implode('.', $excludedcats)), $return, $expiresAt); @@ -633,7 +632,8 @@ class Games ColorCLI::alternateOver(' Title: '). ColorCLI::primary($game['title']). ColorCLI::alternateOver(' Source: '). - ColorCLI::primary($this->_classUsed), true + ColorCLI::primary($this->_classUsed), + true ); } if ($game['cover'] === 1) { @@ -646,7 +646,8 @@ class Games if ($this->echoOutput) { ColorCLI::doEcho( ColorCLI::headerOver('Nothing to update: '). - ColorCLI::primary($game['title'].' (PC)'), true + ColorCLI::primary($game['title'].' (PC)'), + true ); } } @@ -689,7 +690,8 @@ class Games if ($this->echoOutput) { ColorCLI::doEcho( ColorCLI::headerOver('Looking up: '). - ColorCLI::primary($gameInfo['title'].' (PC)'), true + ColorCLI::primary($gameInfo['title'].' (PC)'), + true ); } diff --git a/Blacklight/Movie.php b/Blacklight/Movie.php index f0af70f4d..0e5e8e0b0 100755 --- a/Blacklight/Movie.php +++ b/Blacklight/Movie.php @@ -228,7 +228,18 @@ class Movie public function getMovieRange($page, $cat, array $excludedcats = []) { $sql = Release::query() - ->select( + ->where('r.nzbstatus', '=', 1) + ->where('m.title', '<>', '') + ->where('m.imdbid', '<>', '0000000'); + Releases::showPasswords($sql, true); + if (\count($excludedcats) > 0) { + $sql->whereNotIn('r.categories_id', $excludedcats); + } + + if (\count($cat) > 0 && $cat[0] !== -1) { + Category::getCategorySearch($cat, $sql, true); + } + $sql->select( [ 'm.*', 'g.name as group_name', @@ -257,19 +268,7 @@ class Movie ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') ->join('movieinfo as m', 'm.imdbid', '=', 'r.imdbid') - ->where('r.nzbstatus', '=', 1) - ->where('m.title', '<>', '') - ->where('m.imdbid', '<>', '0000000'); - Releases::showPasswords($sql, true); - if (\count($excludedcats) > 0) { - $sql->whereNotIn('r.categories_id', $excludedcats); - } - - if (\count($cat) > 0 && $cat[0] !== -1) { - Category::getCategorySearch($cat, $sql, true); - } - - $sql->groupBy('m.imdbid') + ->groupBy('m.imdbid') ->orderBy('r.postdate', 'desc'); $return = Cache::get(md5($page.implode('.', $cat).implode('.', $excludedcats))); @@ -277,7 +276,7 @@ class Movie return $return; } - $return = $sql->simplePaginate(config('nntmux.items_per_cover_page')); + $return = $sql->paginate(config('nntmux.items_per_cover_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long')); Cache::put(md5($page.implode('.', $cat).implode('.', $excludedcats)), $return, $expiresAt); @@ -665,7 +664,8 @@ class Movie $mov['year']. ') - '. $mov['imdbid'] - ), true + ), + true ); } diff --git a/Blacklight/Music.php b/Blacklight/Music.php index 7f5ce108e..80b4c3860 100755 --- a/Blacklight/Music.php +++ b/Blacklight/Music.php @@ -148,7 +148,18 @@ class Music public function getMusicRange($page, $cat, array $excludedcats = []) { $sql = Release::query() - ->select( + ->where('r.nzbstatus', '=', 1) + ->where('m.title', '!=', '') + ->where('m.cover', '=', 1); + Releases::showPasswords($sql, true); + if (\count($excludedcats) > 0) { + $sql->whereNotIn('r.categories_id', $excludedcats); + } + + if (\count($cat) > 0 && $cat[0] !== -1) { + Category::getCategorySearch($cat, $sql, true); + } + $sql->select( [ 'm.*', 'r.musicinfo_id', @@ -177,19 +188,7 @@ class Music ->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id') ->join('musicinfo as m', 'm.id', '=', 'r.musicinfo_id') ->join('genres as gn', 'm.genres_id', '=', 'gn.id') - ->where('r.nzbstatus', '=', 1) - ->where('m.title', '!=', '') - ->where('m.cover', '=', 1); - Releases::showPasswords($sql, true); - if (\count($excludedcats) > 0) { - $sql->whereNotIn('r.categories_id', $excludedcats); - } - - if (\count($cat) > 0 && $cat[0] !== -1) { - Category::getCategorySearch($cat, $sql, true); - } - - $sql->groupBy('m.id') + ->groupBy('m.id') ->orderBy('r.postdate', 'desc'); $return = Cache::get(md5($page.implode('.', $cat).implode('.', $excludedcats))); @@ -197,7 +196,7 @@ class Music return $return; } - $return = $sql->simplePaginate(config('nntmux.items_per_cover_page')); + $return = $sql->paginate(config('nntmux.items_per_cover_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long')); Cache::put(md5($page.implode('.', $cat).implode('.', $excludedcats)), $return, $expiresAt); @@ -489,7 +488,8 @@ class Music ColorCLI::alternateOver(' Title: '). ColorCLI::primary($mus['title']). ColorCLI::alternateOver(' Year: '). - ColorCLI::primary($mus['year']), true + ColorCLI::primary($mus['year']), + true ); } $mus['cover'] = $ri->saveImage($musicId, $mus['coverurl'], $this->imgSavePath, 250, 250); @@ -508,7 +508,8 @@ class Music ' ('. $mus['year']. ')' - ), true + ), + true ); } } @@ -621,7 +622,8 @@ class Music ColorCLI::doEcho( ColorCLI::header( 'Processing '.$res->count().' music release(s).' - ), true + ), + true ); } diff --git a/Blacklight/Regexes.php b/Blacklight/Regexes.php index 756b01edb..df112d8b4 100755 --- a/Blacklight/Regexes.php +++ b/Blacklight/Regexes.php @@ -136,7 +136,7 @@ class Regexes } $result->orderBy('id'); - return $result->simplePaginate(config('nntmux.items_per_page')); + return $result->paginate(config('nntmux.items_per_page')); } /** diff --git a/Blacklight/Releases.php b/Blacklight/Releases.php index 28507aa39..f6434993f 100755 --- a/Blacklight/Releases.php +++ b/Blacklight/Releases.php @@ -66,15 +66,14 @@ class Releases } /** - * @param $page + * @param $page * @param array $cat - * @param $orderBy - * @param int $maxAge + * @param $orderBy + * @param int $maxAge * @param array $excludedCats - * @param int $groupName - * @param int $minSize - * - * @return \Illuminate\Contracts\Pagination\Paginator|mixed + * @param int $groupName + * @param int $minSize + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed * @throws \Exception */ public function getBrowseRange($page, array $cat, $orderBy, $maxAge = -1, array $excludedCats = [], $groupName = -1, $minSize = 0) @@ -113,28 +112,12 @@ class Releases ->leftJoin('release_nfos as rn', 're.releases_id', '=', 'r.id') ->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id') ->orderBy($orderBy[0], $orderBy[1]); - self::showPasswords($qry, true); - if ($cat !== [-1]) { - Category::getCategorySearch($cat, $qry, true); - } - if ($maxAge > 0) { - $qry->where('r.postdate', '>', Carbon::now()->subDays($maxAge)); - } - if (\count($excludedCats) > 0) { - $qry->whereNotIn('r.categories_id', $excludedCats); - } - if ($groupName !== -1) { - $qry->where('g.name', $groupName); - } - if ($minSize > 0) { - $qry->where('r.size', '>=', $minSize); - } $releases = Cache::get(md5(implode('.', $cat).implode('.', $orderBy).$maxAge.implode('.', $excludedCats).$minSize.$groupName.$page)); if ($releases !== null) { return $releases; } - $sql = $qry->simplePaginate(config('nntmux.items_per_page')); + $sql = $qry->paginate(config('nntmux.items_per_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium')); Cache::put(md5(implode('.', $cat).implode('.', $orderBy).$maxAge.implode('.', $excludedCats).$minSize.$groupName.$page), $sql, $expiresAt); @@ -381,22 +364,7 @@ class Releases { $sql = Release::query() ->with('group as g', 'nfo as rn', 'category as c', 'failed as df', 'episode as tve') - ->select( - [ - 'r.*', - DB::raw("CONCAT(cp.title, '-', c.title) AS category_name"), - 'g.name as group_name', - 'rn.releases_id as nfoid', - 're.releases_id as reid', - 'tve.firstaired', - 'df.failed as failed', - ] - ) - ->from('releases as r') - ->leftJoin('video_data as re', 're.releases_id', '=', 'r.id') - ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') - ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') - ->whereBetween('r.categories_id', [5000, 5999]) + ->whereBetween('r.categories_id', [Category::TV_ROOT, Category::TV_OTHER]) ->where('r.nzbstatus', NZB::NZB_ADDED); self::showPasswords($sql, true); if (! empty($userShows)) { @@ -420,13 +388,29 @@ class Releases if ($maxAge > 0) { $sql->where('r.postdate', '>', Carbon::now()->subDays($maxAge)); } + $sql->select( + [ + 'r.*', + DB::raw("CONCAT(cp.title, '-', c.title) AS category_name"), + 'g.name as group_name', + 'rn.releases_id as nfoid', + 're.releases_id as reid', + 'tve.firstaired', + 'df.failed as failed', + ] + ) + ->from('releases as r') + ->leftJoin('video_data as re', 're.releases_id', '=', 'r.id') + ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') + ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid'); + if ($orderBy !== '') { $order = $this->getBrowseOrder($orderBy); $sql->orderBy($order[0], $order[1]); } - return $sql->simplePaginate(config('nntmux.items_per_page')); + return $sql->paginate(config('nntmux.items_per_page')); } /** @@ -591,18 +575,6 @@ class Releases $sql = Release::query() ->fromSub(function ($query) use ($maxAge, $groupName, $sizeFrom, $sizeRange, $sizeTo, $hasNfo, $hasComments, $cat, $excludedCats, $type, $daysNew, $daysOld, $searchOptions, $minSize) { - $query->select(['r.*', 'r.categories_id AS category_ids', 'df.failed as failed', 'g.name as group_name', 'rn.releases_id as nfoid', 're.releases_id as reid', 'cp.id as categoryparentid', 'v.tvdb', 'v.trakt', 'v.tvrage', 'v.tvmaze', 'v.imdb', 'v.tmdb', 'tve.firstaired']) - ->selectRaw("CONCAT(cp.title, ' > ', c.title) AS category_name") - ->from('releases as r') - ->leftJoin('video_data as re', 're.releases_id', '=', 'r.id') - ->leftJoin('videos as v', 'v.id', '=', 'r.videos_id') - ->leftJoin('tv_episodes as tve', 'tve.id', '=', 'r.tv_episodes_id') - ->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id') - ->leftJoin('groups as g', 'g.id', '=', 'r.groups_id') - ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') - ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') - ->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id') - ->join('releases_se as rse', 'rse.id', '=', 'r.id'); self::showPasswords($query, true); $query->where('r.nzbstatus', '=', NZB::NZB_ADDED); @@ -651,6 +623,17 @@ class Releases if ($minSize > 0) { $query->where('r.size', '>=', $minSize); } + $query->select(['r.*', 'r.categories_id AS category_ids', 'df.failed as failed', 'g.name as group_name', 'rn.releases_id as nfoid', 're.releases_id as reid', 'cp.id as categoryparentid', 'v.tvdb', 'v.trakt', 'v.tvrage', 'v.tvmaze', 'v.imdb', 'v.tmdb', 'tve.firstaired', DB::raw("CONCAT(cp.title, ' > ', c.title) AS category_name")]) + ->from('releases as r') + ->leftJoin('video_data as re', 're.releases_id', '=', 'r.id') + ->leftJoin('videos as v', 'v.id', '=', 'r.videos_id') + ->leftJoin('tv_episodes as tve', 'tve.id', '=', 'r.tv_episodes_id') + ->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id') + ->leftJoin('groups as g', 'g.id', '=', 'r.groups_id') + ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') + ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') + ->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id') + ->join('releases_se as rse', 'rse.id', '=', 'r.id'); }, 'r') ->orderBy('r.'.$orderBy[0], $orderBy[1]); @@ -659,7 +642,7 @@ class Releases return $releases; } - $releases = $sql->simplePaginate(config('nntmux.items_per_page')); + $releases = $sql->paginate(config('nntmux.items_per_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium')); Cache::put(md5($searchName.$usenetName.$posterName.$fileName.$groupName.$sizeFrom.$sizeTo.$hasNfo.$hasComments.$daysNew.$daysOld.implode('.', $orderBy).$maxAge.implode('.', $excludedCats).$type.implode('.', $cat).$minSize), $releases, $expiresAt); @@ -726,7 +709,20 @@ class Releases } $query = Release::query() - ->select( + ->where('r.nzbstatus', NZB::NZB_ADDED); + self::showPasswords($query, true); + if ($show !== null) { + if ((! empty($series) || ! empty($episode) || ! empty($airdate)) && \strlen((string) $show['episodes']) > 0) { + $query->whereIn('r.tv_episodes_id', $show['episodes']); + } elseif ((int) $show['video'] > 0) { + $query->where('r.videos_id', $show['video']); + // If $series is set but episode is not, return Season Packs only + if (! empty($series) && empty($episode)) { + $query->where('r.tv_epsiodes_id', '=', 0); + } + } + } + $query->select( [ 'r.*', 'v.title', @@ -765,20 +761,8 @@ class Releases ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') ->leftJoin('groups as g', 'g.id', '=', 'r.groups_id') ->leftJoin('video_data as re', 're.releases_id', '=', 'r.id') - ->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id') - ->where('r.nzbstatus', NZB::NZB_ADDED); - self::showPasswords($query, true); - if ($show !== null) { - if ((! empty($series) || ! empty($episode) || ! empty($airdate)) && \strlen((string) $show['episodes']) > 0) { - $query->whereIn('r.tv_episodes_id', $show['episodes']); - } elseif ((int) $show['video'] > 0) { - $query->where('r.videos_id', $show['video']); - // If $series is set but episode is not, return Season Packs only - if (! empty($series) && empty($episode)) { - $query->where('r.tv_epsiodes_id', '=', 0); - } - } - } + ->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id'); + if ($name !== '') { $this->releaseSearch->getSearchSQL(['searchname' => $name], $query, true); @@ -801,7 +785,7 @@ class Releases return $releases; } - $releases = $query->simplePaginate(config('nntmux.items_per_page')); + $releases = $query->paginate(config('nntmux.items_per_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium')); Cache::put(md5($page.implode('.', $siteIdArr).$series.$episode.$airdate.$limit.$name.implode('.', $cat).$maxAge.$minSize), $releases, $expiresAt); @@ -861,7 +845,7 @@ class Releases return $releases; } - $releases = $query->simplePaginate(config('nntmux.items_per_page')); + $releases = $query->paginate(config('nntmux.items_per_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium')); Cache::put(md5($aniDbID.$limit.$name.implode('.', $cat).$maxAge), $releases, $expiresAt); @@ -924,7 +908,7 @@ class Releases return $releases; } - $releases = $query->simplePaginate(config('nntmux.items_per_page')); + $releases = $query->paginate(config('nntmux.items_per_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium')); Cache::put(md5($imDbId.$limit.$name.implode('.', $cat).$maxAge.$minSize), $releases, $expiresAt); diff --git a/Blacklight/XXX.php b/Blacklight/XXX.php index 71afbf501..4b9afa2bf 100755 --- a/Blacklight/XXX.php +++ b/Blacklight/XXX.php @@ -122,7 +122,17 @@ class XXX $order = $this->getXXXOrder($orderBy); $sql = Release::query() - ->select( + ->where('r.nzbstatus', '=', 1) + ->where('xxx.title', '!=', ''); + Releases::showPasswords($sql, true); + if (\count($excludedcats) > 0) { + $sql->whereNotIn('r.categories_id', $excludedcats); + } + + if (\count($cat) > 0 && $cat[0] !== -1) { + Category::getCategorySearch($cat, $sql, true); + } + $sql->select( [ 'xxx.*', DB::raw('UNCOMPRESS(xxx.plot) AS plot'), @@ -152,18 +162,7 @@ class XXX ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') ->join('xxxinfo as xxx', 'xxx.id', '=', 'r.xxxinfo_id') - ->where('r.nzbstatus', '=', 1) - ->where('xxx.title', '!=', ''); - Releases::showPasswords($sql, true); - if (\count($excludedcats) > 0) { - $sql->whereNotIn('r.categories_id', $excludedcats); - } - - if (\count($cat) > 0 && $cat[0] !== -1) { - Category::getCategorySearch($cat, $sql, true); - } - - $sql->groupBy('xxx.id') + ->groupBy('xxx.id') ->orderBy($order[0], $order[1]); $return = Cache::get(md5($page.implode('.', $cat).implode('.', $excludedcats))); @@ -171,7 +170,7 @@ class XXX return $return; } - $return = $sql->simplePaginate(config('nntmux.items_per_cover_page')); + $return = $sql->paginate(config('nntmux.items_per_cover_page')); $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long')); Cache::put(md5($page.implode('.', $cat).implode('.', $excludedcats)), $return, $expiresAt); @@ -563,7 +562,9 @@ class XXX if ($this->echooutput) { ColorCLI::doEcho( - ColorCLI::headerOver(($xxxID !== false ? 'Added/updated XXX movie: '.ColorCLI::primary($mov['title']) : 'Nothing to update for XXX movie: '.ColorCLI::primary($mov['title']))), true); + ColorCLI::headerOver(($xxxID !== false ? 'Added/updated XXX movie: '.ColorCLI::primary($mov['title']) : 'Nothing to update for XXX movie: '.ColorCLI::primary($mov['title']))), + true + ); } return $xxxID; diff --git a/Blacklight/utility/Utility.php b/Blacklight/utility/Utility.php index d7622551c..2b6808112 100755 --- a/Blacklight/utility/Utility.php +++ b/Blacklight/utility/Utility.php @@ -981,7 +981,7 @@ class Utility $range->selectRaw('UNCOMPRESS(plot) AS plot'); } - return $range->orderByDesc('created_at')->simplePaginate(config('nntmux.items_per_page')); + return $range->orderByDesc('created_at')->paginate(config('nntmux.items_per_page')); } /** diff --git a/Changelog b/Changelog index df2d1b7fa..20bce27a3 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-05-09 DariusIII + * Chg: Rearrange pagination queries * Chg: Remove groupBy from getBrowseRange function * Chg: Use simplePaginate method in Releases class * Chg: Update getBrowseRange query in Releases class