1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 01:05:36 +00:00
pixelfed/app/Services/AdminStatsService.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2020-01-23 05:15:11 +00:00
<?php
namespace App\Services;
use Cache;
use App\Util\Lexer\PrettyNumber;
use App\{
Contact,
FailedJob,
Hashtag,
Instance,
Media,
Like,
Profile,
Report,
Status,
User
};
class AdminStatsService
{
public static function get()
{
return array_merge(self::recentData(), self::additionalData());
}
protected static function recentData()
{
$day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day(';
2020-12-18 07:52:49 +00:00
return Cache::remember('admin:dashboard:home:data:v0:15min', now()->addMinutes(15), function() use ($day) {
2020-01-23 05:15:11 +00:00
return [
2020-12-18 07:52:49 +00:00
'contact' => PrettyNumber::convert(Contact::whereNull('read_at')->count()),
'reports' => PrettyNumber::convert(Report::whereNull('admin_seen')->count()),
2020-01-23 05:15:11 +00:00
];
});
}
protected static function additionalData()
{
$day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day(';
2020-12-18 07:52:49 +00:00
return Cache::remember('admin:dashboard:home:data:v0:24hr', now()->addHours(24), function() use ($day) {
2020-01-23 05:15:11 +00:00
return [
2020-12-18 07:52:49 +00:00
'failedjobs' => PrettyNumber::convert(FailedJob::where('failed_at', '>=', \Carbon\Carbon::now()->subDay())->count()),
2020-12-18 09:58:00 +00:00
'statuses' => PrettyNumber::convert(Status::count()),
2020-12-18 07:52:49 +00:00
'profiles' => PrettyNumber::convert(Profile::count()),
'users' => PrettyNumber::convert(User::count()),
'instances' => PrettyNumber::convert(Instance::count()),
'media' => PrettyNumber::convert(Media::count()),
'storage' => Media::sum('size'),
2020-01-23 05:15:11 +00:00
];
});
}
}