diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index 212ee31f0..549349042 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -290,69 +290,32 @@ class PublicApiController extends Controller $max = $request->input('max_id'); $limit = $request->input('limit') ?? 3; $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) ->whereFilterableType('App\Profile') ->whereIn('filter_type', ['mute', 'block']) ->pluck('filterable_id')->toArray(); - if($min || $max) { - $dir = $min ? '>' : '<'; - $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(PublicTimelineService::count() == 0) { + PublicTimelineService::warmCache(true, 400); } + 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); }