Update PixelfedDirectoryController, use cached stats

This commit is contained in:
Daniel Supernault 2024-03-12 00:02:15 -06:00
parent f08aab2231
commit f2f2a8097c
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -7,7 +7,10 @@ use App\Services\AccountService;
use App\Services\StatusService; use App\Services\StatusService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Cache;
use Storage; use Storage;
use App\Status;
use App\User;
class PixelfedDirectoryController extends Controller class PixelfedDirectoryController extends Controller
{ {
@ -137,9 +140,15 @@ class PixelfedDirectoryController extends Controller
'stories' => (bool) config_cache('instance.stories.enabled'), 'stories' => (bool) config_cache('instance.stories.enabled'),
]; ];
$statusesCount = Cache::remember('api:nodeinfo:statuses', 21600, function() {
return Status::whereLocal(true)->count();
});
$usersCount = Cache::remember('api:nodeinfo:users', 43200, function() {
return User::count();
});
$res['stats'] = [ $res['stats'] = [
'user_count' => \App\User::count(), 'user_count' => (int) $usersCount,
'post_count' => \App\Status::whereNull('uri')->count(), 'post_count' => (int) $statusesCount,
]; ];
$res['primary_locale'] = config('app.locale'); $res['primary_locale'] = config('app.locale');