mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-30 16:30:45 +00:00
Update DiscoverController
This commit is contained in:
parent
44e8c23631
commit
8374ebf0f8
1 changed files with 1 additions and 47 deletions
|
@ -21,53 +21,7 @@ class DiscoverController extends Controller
|
||||||
|
|
||||||
public function home(Request $request)
|
public function home(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
return view('discover.home');
|
||||||
'page' => 'nullable|integer|max:50'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$pid = Auth::user()->profile->id;
|
|
||||||
|
|
||||||
$following = Cache::remember('feature:discover:following:'.$pid, 720, function() use($pid) {
|
|
||||||
$following = Follower::select('following_id')
|
|
||||||
->whereProfileId($pid)
|
|
||||||
->pluck('following_id');
|
|
||||||
$filtered = UserFilter::select('filterable_id')
|
|
||||||
->whereUserId($pid)
|
|
||||||
->whereFilterableType('App\Profile')
|
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
|
||||||
->pluck('filterable_id');
|
|
||||||
$following->push($pid);
|
|
||||||
|
|
||||||
if($filtered->count() > 0) {
|
|
||||||
$following->push($filtered);
|
|
||||||
}
|
|
||||||
return $following;
|
|
||||||
});
|
|
||||||
|
|
||||||
$people = Cache::remember('feature:discover:people:'.$pid, 15, function() use($following) {
|
|
||||||
return Profile::select('id', 'name', 'username')->inRandomOrder()
|
|
||||||
->whereHas('statuses')
|
|
||||||
->whereNull('domain')
|
|
||||||
->whereNotIn('id', $following)
|
|
||||||
->whereIsPrivate(false)
|
|
||||||
->take(3)
|
|
||||||
->get();
|
|
||||||
});
|
|
||||||
|
|
||||||
$posts = Status::select('id', 'caption', 'profile_id')
|
|
||||||
->whereHas('media')
|
|
||||||
->whereHas('profile', function($q) {
|
|
||||||
$q->where('is_private', false);
|
|
||||||
})
|
|
||||||
->whereIsNsfw(false)
|
|
||||||
->whereVisibility('public')
|
|
||||||
->where('profile_id', '<>', $pid)
|
|
||||||
->whereNotIn('profile_id', $following)
|
|
||||||
->withCount(['comments', 'likes'])
|
|
||||||
->orderBy('created_at', 'desc')
|
|
||||||
->simplePaginate(21);
|
|
||||||
|
|
||||||
return view('discover.home', compact('people', 'posts'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showTags(Request $request, $hashtag)
|
public function showTags(Request $request, $hashtag)
|
||||||
|
|
Loading…
Reference in a new issue