mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Update PublicApiController, improve home timeline perf
This commit is contained in:
parent
9017f7c4e1
commit
4fe42e5b57
1 changed files with 18 additions and 55 deletions
|
@ -290,69 +290,32 @@ class PublicApiController extends Controller
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 3;
|
$limit = $request->input('limit') ?? 3;
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$amin = SnowflakeService::byDate(now()->subDays(90));
|
|
||||||
|
|
||||||
$key = 'user:last_active_at:id:'.$user->id;
|
|
||||||
$ttl = now()->addMinutes(5);
|
|
||||||
Cache::remember($key, $ttl, function() use($user) {
|
|
||||||
$user->last_active_at = now();
|
|
||||||
$user->save();
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
|
|
||||||
$filtered = UserFilter::whereUserId($user->profile_id)
|
$filtered = UserFilter::whereUserId($user->profile_id)
|
||||||
->whereFilterableType('App\Profile')
|
->whereFilterableType('App\Profile')
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
->pluck('filterable_id')->toArray();
|
->pluck('filterable_id')->toArray();
|
||||||
|
|
||||||
if($min || $max) {
|
if(PublicTimelineService::count() == 0) {
|
||||||
$dir = $min ? '>' : '<';
|
PublicTimelineService::warmCache(true, 400);
|
||||||
$id = $min ?? $max;
|
|
||||||
$timeline = Status::select(
|
|
||||||
'id',
|
|
||||||
'profile_id',
|
|
||||||
'type',
|
|
||||||
'scope',
|
|
||||||
'local'
|
|
||||||
)->where('id', $dir, $id)
|
|
||||||
->where('id', '>', $amin)
|
|
||||||
->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
|
||||||
->whereNotIn('profile_id', $filtered)
|
|
||||||
->whereLocal(true)
|
|
||||||
->whereScope('public')
|
|
||||||
->orderBy('id', 'desc')
|
|
||||||
->limit($limit)
|
|
||||||
->get()
|
|
||||||
->map(function($s) use ($user) {
|
|
||||||
$status = StatusService::get($s->id);
|
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
|
||||||
return $status;
|
|
||||||
});
|
|
||||||
$res = $timeline->toArray();
|
|
||||||
} else {
|
|
||||||
$timeline = Status::select(
|
|
||||||
'id',
|
|
||||||
'profile_id',
|
|
||||||
'type',
|
|
||||||
'scope',
|
|
||||||
'local'
|
|
||||||
)->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
|
||||||
->where('id', '>', $amin)
|
|
||||||
->whereNotIn('profile_id', $filtered)
|
|
||||||
->with('profile', 'hashtags', 'mentions')
|
|
||||||
->whereLocal(true)
|
|
||||||
->whereScope('public')
|
|
||||||
->orderBy('id', 'desc')
|
|
||||||
->limit($limit)
|
|
||||||
->get()
|
|
||||||
->map(function($s) use ($user) {
|
|
||||||
$status = StatusService::get($s->id);
|
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
|
||||||
return $status;
|
|
||||||
});
|
|
||||||
$res = $timeline->toArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($max) {
|
||||||
|
$feed = PublicTimelineService::getRankedMaxId($max, $limit);
|
||||||
|
} else if ($min) {
|
||||||
|
$feed = PublicTimelineService::getRankedMinId($min, $limit);
|
||||||
|
} else {
|
||||||
|
$feed = PublicTimelineService::get(0, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = collect($feed)
|
||||||
|
->map(function($k) use($user) {
|
||||||
|
$status = StatusService::get($k);
|
||||||
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
||||||
|
return $status;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue