mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-22 01:38:49 -05:00
add: Caching for public RSS feeds
This commit is contained in:
@@ -148,7 +148,6 @@ class RssController extends Controller
|
||||
public function show($id, $rsskey)
|
||||
{
|
||||
$user = User::where('rsskey', '=', (string) $rsskey)->firstOrFail();
|
||||
$rss = Rss::where('id', '=', (int) $id)->whereRaw('(user_id = ? OR is_private != ?)', [$user->id, 1])->firstOrFail();
|
||||
|
||||
$banned_group = cache()->rememberForever('banned_group', function () {
|
||||
return Group::where('slug', '=', 'banned')->pluck('id');
|
||||
@@ -167,137 +166,147 @@ class RssController extends Controller
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$search = $rss->object_torrent->search;
|
||||
$description = $rss->object_torrent->description;
|
||||
$uploader = $rss->object_torrent->uploader;
|
||||
$imdb = $rss->object_torrent->imdb;
|
||||
$tvdb = $rss->object_torrent->tvdb;
|
||||
$tmdb = $rss->object_torrent->tmdb;
|
||||
$mal = $rss->object_torrent->mal;
|
||||
$categories = $rss->object_torrent->categories;
|
||||
$types = $rss->object_torrent->types;
|
||||
$genres = $rss->object_torrent->genres;
|
||||
$freeleech = $rss->object_torrent->freeleech;
|
||||
$doubleupload = $rss->object_torrent->doubleupload;
|
||||
$featured = $rss->object_torrent->featured;
|
||||
$stream = $rss->object_torrent->stream;
|
||||
$highspeed = $rss->object_torrent->highspeed;
|
||||
$sd = $rss->object_torrent->sd;
|
||||
$internal = $rss->object_torrent->internal;
|
||||
$alive = $rss->object_torrent->alive;
|
||||
$dying = $rss->object_torrent->dying;
|
||||
$dead = $rss->object_torrent->dead;
|
||||
if (cache()->has('rss'.$id)) {
|
||||
$torrents = cache()->get('rss'.$id);
|
||||
} else {
|
||||
$rss = Rss::where('id', '=', (int) $id)->whereRaw('(user_id = ? OR is_private != ?)', [$user->id, 1])->firstOrFail();
|
||||
|
||||
$terms = explode(' ', $search);
|
||||
$search = '';
|
||||
foreach ($terms as $term) {
|
||||
$search .= '%'.$term.'%';
|
||||
}
|
||||
$search = $rss->object_torrent->search;
|
||||
$description = $rss->object_torrent->description;
|
||||
$uploader = $rss->object_torrent->uploader;
|
||||
$imdb = $rss->object_torrent->imdb;
|
||||
$tvdb = $rss->object_torrent->tvdb;
|
||||
$tmdb = $rss->object_torrent->tmdb;
|
||||
$mal = $rss->object_torrent->mal;
|
||||
$categories = $rss->object_torrent->categories;
|
||||
$types = $rss->object_torrent->types;
|
||||
$genres = $rss->object_torrent->genres;
|
||||
$freeleech = $rss->object_torrent->freeleech;
|
||||
$doubleupload = $rss->object_torrent->doubleupload;
|
||||
$featured = $rss->object_torrent->featured;
|
||||
$stream = $rss->object_torrent->stream;
|
||||
$highspeed = $rss->object_torrent->highspeed;
|
||||
$sd = $rss->object_torrent->sd;
|
||||
$internal = $rss->object_torrent->internal;
|
||||
$alive = $rss->object_torrent->alive;
|
||||
$dying = $rss->object_torrent->dying;
|
||||
$dead = $rss->object_torrent->dead;
|
||||
|
||||
$usernames = explode(' ', $uploader);
|
||||
$uploader = '';
|
||||
foreach ($usernames as $username) {
|
||||
$uploader .= '%'.$username.'%';
|
||||
}
|
||||
|
||||
$keywords = explode(' ', $description);
|
||||
$description = '';
|
||||
foreach ($keywords as $keyword) {
|
||||
$description .= '%'.$keyword.'%';
|
||||
}
|
||||
|
||||
$torrent = Torrent::with(['user', 'category']);
|
||||
|
||||
if ($rss->object_torrent->search) {
|
||||
$torrent->where(function ($query) use ($search) {
|
||||
$query->where('name', 'like', $search);
|
||||
});
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->description) {
|
||||
$torrent->where(function ($query) use ($description) {
|
||||
$query->where('description', 'like', $description)->orWhere('mediainfo', 'like', $description);
|
||||
});
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->uploader && $rss->object_torrent->uploader != null) {
|
||||
$match = User::where('username', 'like', $uploader)->first();
|
||||
if (null === $match) {
|
||||
return ['result' => [], 'count' => 0];
|
||||
$terms = explode(' ', $search);
|
||||
$search = '';
|
||||
foreach ($terms as $term) {
|
||||
$search .= '%'.$term.'%';
|
||||
}
|
||||
$torrent->where('user_id', '=', $match->id)->where('anon', '=', 0);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->imdb && $rss->object_torrent->imdb != null) {
|
||||
$torrent->where('imdb', '=', $imdb);
|
||||
}
|
||||
$usernames = explode(' ', $uploader);
|
||||
$uploader = '';
|
||||
foreach ($usernames as $username) {
|
||||
$uploader .= '%'.$username.'%';
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->tvdb && $rss->object_torrent->tvdb != null) {
|
||||
$torrent->where('tvdb', '=', $tvdb);
|
||||
}
|
||||
$keywords = explode(' ', $description);
|
||||
$description = '';
|
||||
foreach ($keywords as $keyword) {
|
||||
$description .= '%'.$keyword.'%';
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->tmdb && $rss->object_torrent->tmdb != null) {
|
||||
$torrent->where('tmdb', '=', $tmdb);
|
||||
}
|
||||
$torrent = Torrent::with(['user', 'category']);
|
||||
|
||||
if ($rss->object_torrent->mal && $rss->object_torrent->mal != null) {
|
||||
$torrent->where('mal', '=', $mal);
|
||||
}
|
||||
if ($rss->object_torrent->search) {
|
||||
$torrent->where(function ($query) use ($search) {
|
||||
$query->where('name', 'like', $search);
|
||||
});
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->categories && is_array($rss->object_torrent->categories)) {
|
||||
$torrent->whereIn('category_id', $categories);
|
||||
}
|
||||
if ($rss->object_torrent->description) {
|
||||
$torrent->where(function ($query) use ($description) {
|
||||
$query->where('description', 'like', $description)->orWhere('mediainfo', 'like', $description);
|
||||
});
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->types && is_array($rss->object_torrent->types)) {
|
||||
$torrent->whereIn('type', $types);
|
||||
}
|
||||
if ($rss->object_torrent->uploader && $rss->object_torrent->uploader != null) {
|
||||
$match = User::where('username', 'like', $uploader)->first();
|
||||
if (null === $match) {
|
||||
return ['result' => [], 'count' => 0];
|
||||
}
|
||||
$torrent->where('user_id', '=', $match->id)->where('anon', '=', 0);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->genres && is_array($rss->object_torrent->genres)) {
|
||||
$genreID = TagTorrent::select(['torrent_id'])->distinct()->whereIn('tag_name', $genres)->get();
|
||||
$torrent->whereIn('id', $genreID)->cursor();
|
||||
}
|
||||
if ($rss->object_torrent->imdb && $rss->object_torrent->imdb != null) {
|
||||
$torrent->where('imdb', '=', $imdb);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->freeleech && $rss->object_torrent->freeleech != null) {
|
||||
$torrent->where('free', '=', $freeleech);
|
||||
}
|
||||
if ($rss->object_torrent->tvdb && $rss->object_torrent->tvdb != null) {
|
||||
$torrent->where('tvdb', '=', $tvdb);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->doubleupload && $rss->object_torrent->doubleupload != null) {
|
||||
$torrent->where('doubleup', '=', $doubleupload);
|
||||
}
|
||||
if ($rss->object_torrent->tmdb && $rss->object_torrent->tmdb != null) {
|
||||
$torrent->where('tmdb', '=', $tmdb);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->featured && $rss->object_torrent->featured != null) {
|
||||
$torrent->where('featured', '=', $featured);
|
||||
}
|
||||
if ($rss->object_torrent->mal && $rss->object_torrent->mal != null) {
|
||||
$torrent->where('mal', '=', $mal);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->stream && $rss->object_torrent->stream != null) {
|
||||
$torrent->where('stream', '=', $stream);
|
||||
}
|
||||
if ($rss->object_torrent->categories && is_array($rss->object_torrent->categories)) {
|
||||
$torrent->whereIn('category_id', $categories);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->highspeed && $rss->object_torrent->highspeed != null) {
|
||||
$torrent->where('highspeed', '=', $highspeed);
|
||||
}
|
||||
if ($rss->object_torrent->types && is_array($rss->object_torrent->types)) {
|
||||
$torrent->whereIn('type', $types);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->sd && $rss->object_torrent->sd != null) {
|
||||
$torrent->where('sd', '=', $sd);
|
||||
}
|
||||
if ($rss->object_torrent->genres && is_array($rss->object_torrent->genres)) {
|
||||
$genreID = TagTorrent::select(['torrent_id'])->distinct()->whereIn('tag_name', $genres)->get();
|
||||
$torrent->whereIn('id', $genreID)->cursor();
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->internal && $rss->object_torrent->internal != null) {
|
||||
$torrent->where('internal', '=', $internal);
|
||||
}
|
||||
if ($rss->object_torrent->freeleech && $rss->object_torrent->freeleech != null) {
|
||||
$torrent->where('free', '=', $freeleech);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->alive && $rss->object_torrent->alive != null) {
|
||||
$torrent->where('seeders', '>=', $alive);
|
||||
}
|
||||
if ($rss->object_torrent->doubleupload && $rss->object_torrent->doubleupload != null) {
|
||||
$torrent->where('doubleup', '=', $doubleupload);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->dying && $rss->object_torrent->dying != null) {
|
||||
$torrent->where('seeders', '=', $dying)->where('times_completed', '>=', 3);
|
||||
}
|
||||
if ($rss->object_torrent->featured && $rss->object_torrent->featured != null) {
|
||||
$torrent->where('featured', '=', $featured);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->dead && $rss->object_torrent->dead != null) {
|
||||
$torrent->where('seeders', '=', $dead);
|
||||
}
|
||||
if ($rss->object_torrent->stream && $rss->object_torrent->stream != null) {
|
||||
$torrent->where('stream', '=', $stream);
|
||||
}
|
||||
|
||||
$torrents = $torrent->latest()->take(50)->get();
|
||||
if ($rss->object_torrent->highspeed && $rss->object_torrent->highspeed != null) {
|
||||
$torrent->where('highspeed', '=', $highspeed);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->sd && $rss->object_torrent->sd != null) {
|
||||
$torrent->where('sd', '=', $sd);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->internal && $rss->object_torrent->internal != null) {
|
||||
$torrent->where('internal', '=', $internal);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->alive && $rss->object_torrent->alive != null) {
|
||||
$torrent->where('seeders', '>=', $alive);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->dying && $rss->object_torrent->dying != null) {
|
||||
$torrent->where('seeders', '=', $dying)->where('times_completed', '>=', 3);
|
||||
}
|
||||
|
||||
if ($rss->object_torrent->dead && $rss->object_torrent->dead != null) {
|
||||
$torrent->where('seeders', '=', $dead);
|
||||
}
|
||||
|
||||
$torrents = $torrent->latest()->take(50)->get();
|
||||
|
||||
if ($rss->is_private == 0) {
|
||||
cache()->put('rss'.$id, $torrents, 300);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->view('rss.show', ['torrents' => $torrents, 'rsskey' => $user->rsskey])->header('Content-Type', 'text/xml');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user