Update InternalApiController

This commit is contained in:
Daniel Supernault 2018-11-24 23:44:02 -07:00
parent 20fa6fd8e7
commit fa6c3dd3f6
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -125,16 +125,19 @@ class InternalApiController extends Controller
{ {
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$pid = $profile->id; $pid = $profile->id;
//$following = Cache::get('feature:discover:following:'.$profile->id, []); $following = Cache::remember('feature:discover:following:'.$pid, 60, function() use ($pid) {
$following = Follower::whereProfileId($pid)->pluck('following_id'); return Follower::whereProfileId($pid)->pluck('following_id');
});
$filtered = UserFilter::whereUserId($pid) $filters = Cache::remember("user:filter:list:$pid", 60, function() use($pid) {
return UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile') ->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block']) ->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray(); ->pluck('filterable_id')->toArray();
$following = array_merge($following->push($pid)->toArray(), $filtered); });
$following = array_merge($following, $filters);
$people = Profile::select('id', 'name', 'username') $people = Cache::remember('feature:discover:people:'.$pid, 15, function() use ($following) {
return Profile::select('id', 'name', 'username')
->with('avatar') ->with('avatar')
->inRandomOrder() ->inRandomOrder()
->whereHas('statuses') ->whereHas('statuses')
@ -143,9 +146,12 @@ class InternalApiController extends Controller
->whereIsPrivate(false) ->whereIsPrivate(false)
->take(3) ->take(3)
->get(); ->get();
});
$posts = Status::select('id', 'caption', 'profile_id') $posts = Cache::remember('feature:discover:posts:'.$pid, 60, function() use ($following) {
->whereHas('media') return Status::select('id', 'caption', 'profile_id')
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereIsNsfw(false) ->whereIsNsfw(false)
->whereVisibility('public') ->whereVisibility('public')
->whereNotIn('profile_id', $following) ->whereNotIn('profile_id', $following)
@ -153,6 +159,7 @@ class InternalApiController extends Controller
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->take(21) ->take(21)
->get(); ->get();
});
$res = [ $res = [
'people' => $people->map(function($profile) { 'people' => $people->map(function($profile) {