update: queries

This commit is contained in:
HDVinnie
2020-05-26 13:22:18 -04:00
parent 5bc20e40c7
commit 3d3de56ccb
10 changed files with 39 additions and 39 deletions
@@ -56,7 +56,7 @@ class TorrentController extends BaseController
*/
public function index()
{
return new TorrentsResource(Torrent::with(['category', 'tags'])->latest()->paginate());
return new TorrentsResource(Torrent::with(['category', 'type', 'tags'])->latest()->paginate());
}
/**
@@ -119,7 +119,7 @@ class TorrentController extends BaseController
$torrent->tmdb = $request->input('tmdb');
$torrent->mal = $request->input('mal');
$torrent->igdb = $request->input('igdb');
$torrent->type = $request->input('type');
$torrent->type = $request->input('type_id');
$torrent->anon = $request->input('anonymous');
$torrent->stream = $request->input('stream');
$torrent->sd = $request->input('sd');
@@ -148,7 +148,7 @@ class TorrentController extends BaseController
'tmdb' => 'required|numeric',
'mal' => 'required|numeric',
'igdb' => 'required|numeric',
'type' => 'required',
'type_id' => 'required',
'anon' => 'required',
'stream' => 'required',
'sd' => 'required',
+1 -1
View File
@@ -45,7 +45,7 @@ class CategoryController extends Controller
$user = $request->user();
$client = new \App\Services\MovieScrapper(config('api-keys.tmdb'), config('api-keys.tvdb'), config('api-keys.omdb'));
$category = Category::select(['id', 'name'])->findOrFail($id);
$torrents = Torrent::with(['user', 'category'])->withCount(['thanks', 'comments'])->where('category_id', '=', $id)->orderBy('sticky', 'desc')->latest()->paginate(25);
$torrents = Torrent::with(['user', 'category', 'type'])->withCount(['thanks', 'comments'])->where('category_id', '=', $id)->orderBy('sticky', 'desc')->latest()->paginate(25);
$personal_freeleech = PersonalFreeleech::where('user_id', '=', $user->id)->first();
return view('category.show', [
+3 -3
View File
@@ -48,7 +48,7 @@ class GraveyardController extends Controller
{
$current = Carbon::now();
$user = $request->user();
$torrents = Torrent::with('category')->where('created_at', '<', $current->copy()->subDays(30)->toDateTimeString())->paginate(25);
$torrents = Torrent::with('category', 'type')->where('created_at', '<', $current->copy()->subDays(30)->toDateTimeString())->paginate(25);
$repository = $this->faceted;
$deadcount = Torrent::where('seeders', '=', 0)->where('created_at', '<', $current->copy()->subDays(30)->toDateTimeString())->count();
@@ -89,7 +89,7 @@ class GraveyardController extends Controller
$search .= '%'.$term.'%';
}
$torrent = $torrent->with('category')->where('seeders', '=', 0)->where('created_at', '<', $current->copy()->subDays(30)->toDateTimeString());
$torrent = $torrent->with('category', 'type')->where('seeders', '=', 0)->where('created_at', '<', $current->copy()->subDays(30)->toDateTimeString());
if ($request->has('search') && $request->input('search') != null) {
$torrent->where('name', 'like', $search);
@@ -116,7 +116,7 @@ class GraveyardController extends Controller
}
if ($request->has('types') && $request->input('types') != null) {
$torrent->whereIn('type', $types);
$torrent->whereIn('type_id', $types);
}
if ($request->has('sorting') && $request->input('sorting') != null) {
+5 -5
View File
@@ -58,25 +58,25 @@ class HomeController extends Controller
// Latest Torrents Block
$personal_freeleech = PersonalFreeleech::where('user_id', '=', $user->id)->first();
$newest = cache()->remember('newest_torrents', $expiresAt, fn () => Torrent::with(['user', 'category'])
$newest = cache()->remember('newest_torrents', $expiresAt, fn () => Torrent::with(['user', 'category', 'type'])
->withCount(['thanks', 'comments'])
->latest()
->take(5)
->get());
$seeded = cache()->remember('seeded_torrents', $expiresAt, fn () => Torrent::with(['user', 'category'])
$seeded = cache()->remember('seeded_torrents', $expiresAt, fn () => Torrent::with(['user', 'category', 'type'])
->withCount(['thanks', 'comments'])
->latest('seeders')
->take(5)
->get());
$leeched = cache()->remember('leeched_torrents', $expiresAt, fn () => Torrent::with(['user', 'category'])
$leeched = cache()->remember('leeched_torrents', $expiresAt, fn () => Torrent::with(['user', 'category', 'type'])
->withCount(['thanks', 'comments'])
->latest('leechers')
->take(5)
->get());
$dying = cache()->remember('dying_torrents', $expiresAt, fn () => Torrent::with(['user', 'category'])
$dying = cache()->remember('dying_torrents', $expiresAt, fn () => Torrent::with(['user', 'category', 'type'])
->withCount(['thanks', 'comments'])
->where('seeders', '=', 1)
->where('times_completed', '>=', 1)
@@ -84,7 +84,7 @@ class HomeController extends Controller
->take(5)
->get());
$dead = cache()->remember('dead_torrents', $expiresAt, fn () => Torrent::with(['user', 'category'])
$dead = cache()->remember('dead_torrents', $expiresAt, fn () => Torrent::with(['user', 'category', 'type'])
->withCount(['thanks', 'comments'])
->where('seeders', '=', 0)
->latest('leechers')
+5 -5
View File
@@ -79,7 +79,7 @@ class RequestController extends Controller
$claimed_bounty = TorrentRequest::whereNotNull('filled_by')->sum('bounty');
$unclaimed_bounty = TorrentRequest::whereNull('filled_by')->sum('bounty');
$torrentRequests = TorrentRequest::with(['user', 'category'])->paginate(25);
$torrentRequests = TorrentRequest::with(['user', 'category', 'type'])->paginate(25);
$repository = $this->faceted;
return view('requests.requests', [
@@ -125,7 +125,7 @@ class RequestController extends Controller
$search .= '%'.$term.'%';
}
$torrentRequest = $torrentRequest->with(['user', 'category']);
$torrentRequest = $torrentRequest->with(['user', 'category', 'type']);
if ($request->has('search') && $request->input('search') != null) {
$torrentRequest->where('name', 'like', $search);
@@ -156,7 +156,7 @@ class RequestController extends Controller
}
if ($request->has('types') && $request->input('types') != null) {
$torrentRequest->whereIn('type', $types);
$torrentRequest->whereIn('type_id', $types);
}
if ($request->has('unfilled') && $request->input('unfilled') != null) {
@@ -309,7 +309,7 @@ class RequestController extends Controller
$tr->tmdb = $request->input('tmdb');
$tr->mal = $request->input('mal');
$tr->igdb = $request->input('igdb');
$tr->type = $request->input('type');
$tr->type = $request->input('type_id');
$tr->bounty = $request->input('bounty');
$tr->votes = 1;
$tr->anon = $request->input('anon');
@@ -408,7 +408,7 @@ class RequestController extends Controller
$mal = $request->input('mal');
$igdb = $request->input('igdb');
$category = $request->input('category_id');
$type = $request->input('type');
$type = $request->input('type_id');
$description = $request->input('description');
$anon = $request->input('anon');
+2 -2
View File
@@ -206,7 +206,7 @@ class RssController extends Controller
$description .= '%'.$keyword.'%';
}
$torrent = Torrent::with(['user', 'category']);
$torrent = Torrent::with(['user', 'category', 'type']);
if ($rss->object_torrent->search) {
$torrent->where(function ($query) use ($search) {
@@ -249,7 +249,7 @@ class RssController extends Controller
}
if ($rss->object_torrent->types && is_array($rss->object_torrent->types)) {
$torrent->whereIn('type', $types);
$torrent->whereIn('type_id', $types);
}
if ($rss->object_torrent->genres && is_array($rss->object_torrent->genres)) {
@@ -46,9 +46,9 @@ class ModerationController extends Controller
public function index()
{
$current = Carbon::now();
$pending = Torrent::with(['user', 'category'])->pending()->get();
$postponed = Torrent::with(['user', 'category'])->postponed()->get();
$rejected = Torrent::with(['user', 'category'])->rejected()->get();
$pending = Torrent::with(['user', 'category', 'type'])->pending()->get();
$postponed = Torrent::with(['user', 'category', 'type'])->postponed()->get();
$rejected = Torrent::with(['user', 'category', 'type'])->rejected()->get();
return view('Staff.moderation.index', [
'current' => $current,
+13 -13
View File
@@ -108,7 +108,7 @@ class TorrentController extends Controller
$user = $request->user();
$repository = $this->faceted;
$torrents = Torrent::with(['user', 'category', 'tags'])->withCount(['thanks', 'comments'])->orderBy('sticky', 'desc')->orderBy('created_at', 'desc')->paginate(25);
$torrents = Torrent::with(['user', 'category', 'type', 'tags'])->withCount(['thanks', 'comments'])->orderBy('sticky', 'desc')->orderBy('created_at', 'desc')->paginate(25);
$personal_freeleech = PersonalFreeleech::where('user_id', '=', $user->id)->first();
$bookmarks = Bookmark::where('user_id', $user->id)->get();
@@ -137,7 +137,7 @@ class TorrentController extends Controller
{
$user = $request->user();
$personal_freeleech = PersonalFreeleech::where('user_id', '=', $user->id)->first();
$torrents = Torrent::with(['user', 'category'])
$torrents = Torrent::with(['user', 'category', 'type'])
->withCount(['thanks', 'comments'])
->where('category_id', '=', $category_id)
->where('tmdb', '=', $tmdb)
@@ -169,7 +169,7 @@ class TorrentController extends Controller
public function cardLayout(Request $request)
{
$user = $request->user();
$torrents = Torrent::with(['user', 'category'])->latest()->paginate(33);
$torrents = Torrent::with(['user', 'category', 'type'])->latest()->paginate(33);
$repository = $this->faceted;
$client = new \App\Services\MovieScrapper(config('api-keys.tmdb'), config('api-keys.tvdb'), config('api-keys.omdb'));
@@ -261,7 +261,7 @@ class TorrentController extends Controller
}
$totals = [];
$counts = [];
$launcher = Torrent::with(['user', 'category'])->withCount(['thanks', 'comments'])->whereIn('imdb', $fed)->orderBy(self::SORTING, self::ORDER);
$launcher = Torrent::with(['user', 'category', 'type'])->withCount(['thanks', 'comments'])->whereIn('imdb', $fed)->orderBy(self::SORTING, self::ORDER);
foreach ($launcher->cursor() as $chunk) {
if ($chunk->imdb) {
$totals[$chunk->imdb] = ! array_key_exists($chunk->imdb, $totals) ? 1 : $totals[$chunk->imdb] + 1;
@@ -567,7 +567,7 @@ class TorrentController extends Controller
if (! $history || ! is_array($history)) {
$history = [];
}
$torrent = $torrent->with(['user', 'category', 'tags'])->withCount(['thanks', 'comments'])->whereNotIn('torrents.id', $history);
$torrent = $torrent->with(['user', 'category', 'type', 'tags'])->withCount(['thanks', 'comments'])->whereNotIn('torrents.id', $history);
} elseif ($history == 1) {
$torrent = History::where('history.user_id', '=', $user->id);
$torrent->where(function ($query) use ($user, $seedling, $downloaded, $leeching, $idling) {
@@ -596,7 +596,7 @@ class TorrentController extends Controller
$join->on('history.info_hash', '=', 'torrents.info_hash');
})->groupBy('torrents.id');
} else {
$torrent = $torrent->with(['user', 'category', 'tags'])->withCount(['thanks', 'comments']);
$torrent = $torrent->with(['user', 'category', 'type', 'tags'])->withCount(['thanks', 'comments']);
}
if ($collection != 1) {
if ($request->has('search') && $request->input('search') != null) {
@@ -723,7 +723,7 @@ class TorrentController extends Controller
}
$totals = [];
$counts = [];
$launcher = Torrent::with(['user', 'category', 'tags'])->withCount(['thanks', 'comments'])->whereIn('imdb', $fed)->orderBy($sorting, $order);
$launcher = Torrent::with(['user', 'category', 'type', 'tags'])->withCount(['thanks', 'comments'])->whereIn('imdb', $fed)->orderBy($sorting, $order);
foreach ($launcher->cursor() as $chunk) {
if ($chunk->imdb) {
$totals[$chunk->imdb] = ! array_key_exists($chunk->imdb, $totals) ? 1 : $totals[$chunk->imdb] + 1;
@@ -780,7 +780,7 @@ class TorrentController extends Controller
if (is_array($hungry) && array_key_exists($page - 1, $hungry)) {
$fed = $hungry[$page - 1];
}
$torrents = Torrent::with(['user', 'category', 'tags'])->withCount(['thanks', 'comments'])->whereIn('id', $fed)->orderBy($sorting, $order)->get();
$torrents = Torrent::with(['user', 'category', 'type', 'tags'])->withCount(['thanks', 'comments'])->whereIn('id', $fed)->orderBy($sorting, $order)->get();
} else {
$torrents = $torrent->orderBy('sticky', 'desc')->orderBy($sorting, $order)->paginate($qty);
}
@@ -902,7 +902,7 @@ class TorrentController extends Controller
*/
public function torrent(Request $request, $id)
{
$torrent = Torrent::withAnyStatus()->with(['comments', 'category', 'subtitles'])->findOrFail($id);
$torrent = Torrent::withAnyStatus()->with(['comments', 'category', 'type', 'subtitles'])->findOrFail($id);
$uploader = $torrent->user;
$user = $request->user();
$freeleech_token = FreeleechToken::where('user_id', '=', $user->id)->where('torrent_id', '=', $torrent->id)->first();
@@ -1051,7 +1051,7 @@ class TorrentController extends Controller
$torrent->tmdb = $request->input('tmdb');
$torrent->mal = $request->input('mal');
$torrent->igdb = $request->input('igdb');
$torrent->type = $request->input('type');
$torrent->type = $request->input('type_id');
$torrent->mediainfo = $request->input('mediainfo');
$torrent->anon = $request->input('anonymous');
$torrent->stream = $request->input('stream');
@@ -1068,7 +1068,7 @@ class TorrentController extends Controller
'tmdb' => 'required|numeric',
'mal' => 'required|numeric',
'igdb' => 'required|numeric',
'type' => 'required',
'type_id' => 'required',
'anon' => 'required',
'stream' => 'required',
'sd' => 'required',
@@ -1316,7 +1316,7 @@ class TorrentController extends Controller
$torrent->tmdb = $request->input('tmdb');
$torrent->mal = $request->input('mal');
$torrent->igdb = $request->input('igdb');
$torrent->type = $request->input('type');
$torrent->type = $request->input('type_id');
$torrent->anon = $request->input('anonymous');
$torrent->stream = $request->input('stream');
$torrent->sd = $request->input('sd');
@@ -1341,7 +1341,7 @@ class TorrentController extends Controller
'tmdb' => 'required|numeric',
'mal' => 'required|numeric',
'igdb' => 'required|numeric',
'type' => 'required',
'type_id' => 'required',
'anon' => 'required',
'stream' => 'required',
'sd' => 'required',
+3 -3
View File
@@ -1247,7 +1247,7 @@ class UserController extends Controller
}
if ($request->has('view') && $request->input('view') == 'requests') {
$torrentRequests = TorrentRequest::with(['user', 'category']);
$torrentRequests = TorrentRequest::with(['user', 'category', 'type']);
$order = null;
$sorting = null;
if ($request->has('name') && $request->input('name') != null) {
@@ -1704,7 +1704,7 @@ class UserController extends Controller
if (($request->user()->id == $user->id || $request->user()->group->is_modo)) {
$logger = 'user.private.requests';
$torrentRequests = TorrentRequest::with(['user', 'category'])->where('user_id', '=', $user->id)->latest()->paginate(25);
$torrentRequests = TorrentRequest::with(['user', 'category', 'type'])->where('user_id', '=', $user->id)->latest()->paginate(25);
return view($logger, [
'route' => 'requests',
@@ -1713,7 +1713,7 @@ class UserController extends Controller
]);
}
$logger = 'user.requests';
$torrentRequests = TorrentRequest::with(['user', 'category'])->where('user_id', '=', $user->id)->where('anon', '!=', 1)->latest()->paginate(25);
$torrentRequests = TorrentRequest::with(['user', 'category', 'type'])->where('user_id', '=', $user->id)->where('anon', '!=', 1)->latest()->paginate(25);
return view($logger, [
'route' => 'requests',
+1 -1
View File
@@ -33,7 +33,7 @@ class TorrentResource extends JsonResource
'name' => $this->name,
'release_year' => $this->release_year,
'category' => $this->category->name,
'type' => $this->type,
'type' => $this->type->name,
'size' => $this->getSize(),
'seeders' => $this->seeders,
'leechers' => $this->leechers,