mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-23 06:51:27 +00:00
Refactor discover accounts endpoint, cache popular accounts and remove following check as most invocations are from new accounts
This commit is contained in:
parent
101676758e
commit
016b11f301
1 changed files with 13 additions and 11 deletions
|
@ -3028,21 +3028,23 @@ class ApiV1Controller extends Controller
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
$ids = DB::table('profiles')
|
$ids = Cache::remember('api:v1.1:discover:accounts:popular', 86400, function() {
|
||||||
|
return DB::table('profiles')
|
||||||
->where('is_private', false)
|
->where('is_private', false)
|
||||||
->whereNull('status')
|
->whereNull('status')
|
||||||
->orderByDesc('profiles.followers_count')
|
->orderByDesc('profiles.followers_count')
|
||||||
->limit(20)
|
->limit(20)
|
||||||
->get();
|
->get();
|
||||||
|
});
|
||||||
|
|
||||||
$ids = $ids->map(function($profile) {
|
$ids = $ids->map(function($profile) {
|
||||||
return AccountService::getMastodon($profile->id);
|
return AccountService::getMastodon($profile->id, true);
|
||||||
})
|
})
|
||||||
->filter(function($profile) use($pid) {
|
->filter(function($profile) use($pid) {
|
||||||
return $profile &&
|
return $profile && isset($profile['id']);
|
||||||
isset($profile['id']) &&
|
})
|
||||||
!FollowerService::follows($pid, $profile['id']) &&
|
->filter(function($profile) use($pid) {
|
||||||
$profile['id'] != $pid;
|
return $profile['id'] != $pid;
|
||||||
})
|
})
|
||||||
->take(6)
|
->take(6)
|
||||||
->values();
|
->values();
|
||||||
|
|
Loading…
Reference in a new issue