mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update PublicApiController, improve network timeline perf
This commit is contained in:
parent
1e3d3a69d2
commit
e5f683fda4
1 changed files with 27 additions and 44 deletions
|
@ -15,7 +15,7 @@ use App\{
|
||||||
StatusView,
|
StatusView,
|
||||||
UserFilter
|
UserFilter
|
||||||
};
|
};
|
||||||
use Auth,Cache;
|
use Auth, Cache;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
use App\Transformer\Api\{
|
use App\Transformer\Api\{
|
||||||
|
@ -27,6 +27,8 @@ use App\Transformer\Api\{
|
||||||
use App\Services\{
|
use App\Services\{
|
||||||
AccountService,
|
AccountService,
|
||||||
PublicTimelineService,
|
PublicTimelineService,
|
||||||
|
StatusService,
|
||||||
|
SnowflakeService,
|
||||||
UserFilterService
|
UserFilterService
|
||||||
};
|
};
|
||||||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||||
|
@ -498,6 +500,7 @@ 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;
|
$key = 'user:last_active_at:id:'.$user->id;
|
||||||
$ttl = now()->addMinutes(5);
|
$ttl = now()->addMinutes(5);
|
||||||
|
@ -513,61 +516,41 @@ class PublicApiController extends Controller
|
||||||
$timeline = Status::select(
|
$timeline = Status::select(
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'caption',
|
|
||||||
'rendered',
|
|
||||||
'profile_id',
|
|
||||||
'type',
|
'type',
|
||||||
'in_reply_to_id',
|
|
||||||
'reblog_of_id',
|
|
||||||
'is_nsfw',
|
|
||||||
'scope',
|
'scope',
|
||||||
'local',
|
|
||||||
'reply_count',
|
|
||||||
'comments_disabled',
|
|
||||||
'place_id',
|
|
||||||
'likes_count',
|
|
||||||
'reblogs_count',
|
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
|
||||||
)->where('id', $dir, $id)
|
)->where('id', $dir, $id)
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereNotNull('uri')
|
->whereNotNull('uri')
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
->where('created_at', '>', now()->subMonths(3))
|
->where('id', '>', $amin)
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get();
|
->get()
|
||||||
|
->map(function($s) {
|
||||||
|
return StatusService::get($s->id);
|
||||||
|
});
|
||||||
|
$res = $timeline->toArray();
|
||||||
} else {
|
} else {
|
||||||
$timeline = Status::select(
|
$timeline = Status::select(
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'caption',
|
'type',
|
||||||
'rendered',
|
'scope',
|
||||||
'profile_id',
|
'created_at',
|
||||||
'type',
|
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
'in_reply_to_id',
|
->whereNotNull('uri')
|
||||||
'reblog_of_id',
|
->whereScope('public')
|
||||||
'is_nsfw',
|
->where('id', '>', $amin)
|
||||||
'scope',
|
->orderBy('created_at', 'desc')
|
||||||
'local',
|
->limit($limit)
|
||||||
'reply_count',
|
->get()
|
||||||
'comments_disabled',
|
->map(function($s) {
|
||||||
'created_at',
|
return StatusService::get($s->id);
|
||||||
'place_id',
|
});
|
||||||
'likes_count',
|
$res = $timeline->toArray();
|
||||||
'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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
|
||||||
$res = $this->fractal->createData($fractal)->toArray();
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue