1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-23 08:14:10 +00:00

Update PublicApiController, improve network timeline perf

This commit is contained in:
Daniel Supernault 2021-06-29 01:23:24 -06:00
parent 1e3d3a69d2
commit e5f683fda4
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -15,7 +15,7 @@ use App\{
StatusView,
UserFilter
};
use Auth,Cache;
use Auth, Cache;
use Carbon\Carbon;
use League\Fractal;
use App\Transformer\Api\{
@ -27,6 +27,8 @@ use App\Transformer\Api\{
use App\Services\{
AccountService,
PublicTimelineService,
StatusService,
SnowflakeService,
UserFilterService
};
use App\Jobs\StatusPipeline\NewStatusPipeline;
@ -498,6 +500,7 @@ 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);
@ -513,61 +516,41 @@ class PublicApiController extends Controller
$timeline = Status::select(
'id',
'uri',
'caption',
'rendered',
'profile_id',
'type',
'in_reply_to_id',
'reblog_of_id',
'is_nsfw',
'scope',
'local',
'reply_count',
'comments_disabled',
'place_id',
'likes_count',
'reblogs_count',
'created_at',
'updated_at'
)->where('id', $dir, $id)
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotNull('uri')
->whereScope('public')
->where('created_at', '>', now()->subMonths(3))
->where('id', '>', $amin)
->orderBy('created_at', 'desc')
->limit($limit)
->get();
->get()
->map(function($s) {
return StatusService::get($s->id);
});
$res = $timeline->toArray();
} else {
$timeline = Status::select(
'id',
'uri',
'caption',
'rendered',
'profile_id',
'type',
'in_reply_to_id',
'reblog_of_id',
'is_nsfw',
'scope',
'local',
'reply_count',
'comments_disabled',
'created_at',
'place_id',
'likes_count',
'reblogs_count',
'updated_at'
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->with('profile', 'hashtags', 'mentions')
->whereNotNull('uri')
->whereScope('public')
->where('created_at', '>', now()->subMonths(3))
->orderBy('created_at', 'desc')
->simplePaginate($limit);
$timeline = Status::select(
'id',
'uri',
'type',
'scope',
'created_at',
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotNull('uri')
->whereScope('public')
->where('id', '>', $amin)
->orderBy('created_at', 'desc')
->limit($limit)
->get()
->map(function($s) {
return StatusService::get($s->id);
});
$res = $timeline->toArray();
}
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
$res = $this->fractal->createData($fractal)->toArray();
return response()->json($res);
}