mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 09:17:03 +00:00
Update DiscoverController
This commit is contained in:
parent
44f5ce7220
commit
d50e9c4df9
1 changed files with 9 additions and 3 deletions
|
@ -29,7 +29,7 @@ class DiscoverController extends Controller
|
||||||
public function showTags(Request $request, $hashtag)
|
public function showTags(Request $request, $hashtag)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'page' => 'nullable|integer|min:1|max:10',
|
'page' => 'nullable|integer|min:1|max:20',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$tag = Hashtag::with('posts')
|
$tag = Hashtag::with('posts')
|
||||||
|
@ -37,7 +37,12 @@ class DiscoverController extends Controller
|
||||||
->whereSlug($hashtag)
|
->whereSlug($hashtag)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
$posts = $tag->posts()
|
$page = $request->input('page') ?? 1;
|
||||||
|
$key = 'discover:tag-'.$tag->id.':page-'.$page;
|
||||||
|
$keyMinutes = $page > 1 ? 5 : 2;
|
||||||
|
|
||||||
|
$posts = Cache::remember($key, now()->addMinutes($keyMinutes), function() use ($tag, $request) {
|
||||||
|
return $tag->posts()
|
||||||
->whereNull('url')
|
->whereNull('url')
|
||||||
->whereNull('uri')
|
->whereNull('uri')
|
||||||
->whereHas('media')
|
->whereHas('media')
|
||||||
|
@ -45,7 +50,8 @@ class DiscoverController extends Controller
|
||||||
->whereIsNsfw(false)
|
->whereIsNsfw(false)
|
||||||
->whereVisibility('public')
|
->whereVisibility('public')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->simplePaginate(12);
|
->simplePaginate(24);
|
||||||
|
});
|
||||||
|
|
||||||
if($posts->count() == 0) {
|
if($posts->count() == 0) {
|
||||||
abort(404);
|
abort(404);
|
||||||
|
|
Loading…
Reference in a new issue