diff --git a/app/Services/AdminStatsService.php b/app/Services/AdminStatsService.php index 6c389e0c..3f1f1a74 100644 --- a/app/Services/AdminStatsService.php +++ b/app/Services/AdminStatsService.php @@ -6,6 +6,7 @@ use Cache; use DB; use App\Util\Lexer\PrettyNumber; use App\{ + Avatar, Contact, FailedJob, Hashtag, @@ -31,6 +32,43 @@ class AdminStatsService ); } + public static function storage() + { + return Cache::remember('admin:dashboard:storage:stats', 120000, function() { + $res = []; + + $res['last_updated'] = now()->format('c'); + + $avatars = Avatar::count(); + $avatarsLocal = Avatar::whereNull('cdn_url')->count(); + $res['avatar'] = [ + 'count' => $avatars, + 'local_count' => $avatarsLocal, + 'cloud_count' => ($avatars - $avatarsLocal), + 'total_sum' => Avatar::sum('size') + ]; + + $media = Media::count(); + $mediaSum = Media::sum('size'); + $mediaLocalSum = Media::whereNotNull('user_id')->sum('size'); + $mediaLocal = Media::whereNotNull('user_id')->count(); + $res['media'] = [ + 'count' => $media, + 'local_count' => $mediaLocal, + 'cloud_count' => ($media - $mediaLocal), + 'total_sum' => $mediaSum, + 'local_sum' => $mediaLocalSum, + 'local_30d' => Media::whereNotNull('user_id')->where('created_at', '>', now()->subDays(30))->sum('size'), + 'cloud_30d' => Media::whereNull('user_id')->where('created_at', '>', now()->subDays(30))->sum('size'), + 'cloud_sum' => ($mediaSum - $mediaLocalSum), + 'avg_size' => Media::avg('size'), + 'avg_mime' => Media::groupBy('mime')->orderByRaw('COUNT(*) DESC')->first()->mime, + ]; + + return $res; + }); + } + protected static function recentData() { $day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day('; @@ -68,8 +106,8 @@ class AdminStatsService { $ttl = now()->addHours(12); return Cache::remember('admin:dashboard:home:data-postsGraph:v0.1:24hr', $ttl, function() { - $gb = config('database.default') == 'pgsql' ? ['statuses.id', DB::raw('Date(created_at)')] : DB::raw('Date(created_at)'); - $s = Status::selectRaw('Date(created_at) as date, count(statuses.id) as count, statuses.*') + $gb = config('database.default') == 'pgsql' ? ['statuses.id', 'created_at'] : DB::raw('Date(created_at)'); + $s = Status::selectRaw('Date(created_at) as date, count(statuses.id) as count') ->where('created_at', '>=', now()->subWeek()) ->groupBy($gb) ->orderBy('created_at', 'DESC') @@ -86,7 +124,7 @@ class AdminStatsService $dates = collect($dates)->merge($s); - $s = Status::selectRaw('Date(created_at) as date, count(statuses.id) as count, statuses.*') + $s = Status::selectRaw('Date(created_at) as date, count(statuses.id) as count') ->where('created_at', '>=', now()->subWeeks(2)) ->where('created_at', '<=', now()->subWeeks(1)) ->groupBy($gb) diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 827cbdb1..549c55ad 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -5,10 +5,10 @@