mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-12 17:44:31 +00:00
Update ApiV1Controller, add network timeline support via NetworkTimelineService
This commit is contained in:
parent
37f97ccc2d
commit
f54fd6e9cc
1 changed files with 35 additions and 13 deletions
|
@ -62,6 +62,7 @@ use App\Services\{
|
||||||
FollowerService,
|
FollowerService,
|
||||||
InstanceService,
|
InstanceService,
|
||||||
LikeService,
|
LikeService,
|
||||||
|
NetworkTimelineService,
|
||||||
NotificationService,
|
NotificationService,
|
||||||
MediaPathService,
|
MediaPathService,
|
||||||
PublicTimelineService,
|
PublicTimelineService,
|
||||||
|
@ -1899,28 +1900,46 @@ class ApiV1Controller extends Controller
|
||||||
$this->validate($request,[
|
$this->validate($request,[
|
||||||
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'limit' => 'nullable|integer|max:100'
|
'limit' => 'nullable|integer|max:100',
|
||||||
|
'remote' => 'sometimes'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 20;
|
$limit = $request->input('limit') ?? 20;
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
$remote = $request->has('remote');
|
||||||
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
||||||
|
|
||||||
Cache::remember('api:v1:timelines:public:cache_check', 10368000, function() {
|
if($remote && config('instance.timeline.network.cached')) {
|
||||||
if(PublicTimelineService::count() == 0) {
|
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function() {
|
||||||
PublicTimelineService::warmCache(true, 400);
|
if(NetworkTimelineService::count() == 0) {
|
||||||
}
|
NetworkTimelineService::warmCache(true, config('instance.timeline.network.cache_dropoff'));
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if ($max) {
|
if ($max) {
|
||||||
$feed = PublicTimelineService::getRankedMaxId($max, $limit + 5);
|
$feed = NetworkTimelineService::getRankedMaxId($max, $limit + 5);
|
||||||
} else if ($min) {
|
} else if ($min) {
|
||||||
$feed = PublicTimelineService::getRankedMinId($min, $limit + 5);
|
$feed = NetworkTimelineService::getRankedMinId($min, $limit + 5);
|
||||||
} else {
|
} else {
|
||||||
$feed = PublicTimelineService::get(0, $limit + 5);
|
$feed = NetworkTimelineService::get(0, $limit + 5);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Cache::remember('api:v1:timelines:public:cache_check', 10368000, function() {
|
||||||
|
if(PublicTimelineService::count() == 0) {
|
||||||
|
PublicTimelineService::warmCache(true, 400);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($max) {
|
||||||
|
$feed = PublicTimelineService::getRankedMaxId($max, $limit + 5);
|
||||||
|
} else if ($min) {
|
||||||
|
$feed = PublicTimelineService::getRankedMinId($min, $limit + 5);
|
||||||
|
} else {
|
||||||
|
$feed = PublicTimelineService::get(0, $limit + 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$res = collect($feed)
|
$res = collect($feed)
|
||||||
->map(function($k) use($user) {
|
->map(function($k) use($user) {
|
||||||
|
@ -1943,6 +1962,9 @@ class ApiV1Controller extends Controller
|
||||||
// ->toArray();
|
// ->toArray();
|
||||||
|
|
||||||
$baseUrl = config('app.url') . '/api/v1/timelines/public?limit=' . $limit . '&';
|
$baseUrl = config('app.url') . '/api/v1/timelines/public?limit=' . $limit . '&';
|
||||||
|
if($remote) {
|
||||||
|
$baseUrl .= 'remote=1&';
|
||||||
|
}
|
||||||
$minId = $res->map(function($s) {
|
$minId = $res->map(function($s) {
|
||||||
return ['id' => $s['id']];
|
return ['id' => $s['id']];
|
||||||
})->min('id');
|
})->min('id');
|
||||||
|
|
Loading…
Reference in a new issue