diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 8cacd6fb6..37e3a7c0d 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -6,6 +6,7 @@ use App\{ AccountInterstitial, Contact, Hashtag, + Instance, Newsroom, OauthClient, Profile, @@ -31,6 +32,7 @@ use App\Http\Controllers\Admin\{ }; use Illuminate\Validation\Rule; use App\Services\AdminStatsService; +use App\Services\AccountService; use App\Services\StatusService; use App\Services\StoryService; use App\Models\CustomEmoji; @@ -54,9 +56,71 @@ class AdminController extends Controller } public function home() + { + return view('admin.home'); + } + + public function stats() { $data = AdminStatsService::get(); - return view('admin.home', compact('data')); + return view('admin.stats', compact('data')); + } + + public function getStats() + { + return AdminStatsService::summary(); + } + + public function getAccounts() + { + $users = User::orderByDesc('id')->cursorPaginate(10); + + $res = [ + "next_page_url" => $users->nextPageUrl(), + "data" => $users->map(function($user) { + $account = AccountService::get($user->profile_id, true); + if(!$account) { + return [ + "id" => $user->profile_id, + "username" => $user->username, + "status" => "deleted", + "avatar" => "/storage/avatars/default.jpg", + "created_at" => $user->created_at + ]; + } + $account['user_id'] = $user->id; + return $account; + }) + ->filter(function($user) { + return $user; + }) + ]; + return $res; + } + + public function getPosts() + { + $posts = DB::table('statuses') + ->orderByDesc('id') + ->cursorPaginate(10); + + $res = [ + "next_page_url" => $posts->nextPageUrl(), + "data" => $posts->map(function($post) { + $status = StatusService::get($post->id, false); + if(!$status) { + return ["id" => $post->id, "created_at" => $post->created_at]; + } + return $status; + }) + ]; + + return $res; + } + + public function getInstances() + { + return Instance::orderByDesc('id')->cursorPaginate(10); } public function statuses(Request $request) diff --git a/app/Services/AdminStatsService.php b/app/Services/AdminStatsService.php index dbd52276e..2117207f3 100644 --- a/app/Services/AdminStatsService.php +++ b/app/Services/AdminStatsService.php @@ -26,10 +26,18 @@ class AdminStatsService public static function get() { return array_merge( - self::recentData(), - self::additionalData(), - self::postsGraph() - ); + self::recentData(), + self::additionalData(), + self::postsGraph() + ); + } + + public static function summary() + { + return array_merge( + self::recentData(), + self::additionalDataSummary(), + ); } public static function storage() @@ -102,6 +110,19 @@ class AdminStatsService }); } + protected static function additionalDataSummary() + { + $ttl = now()->addHours(24); + return Cache::remember('admin:dashboard:home:data:v0:24hr', $ttl, function() { + return [ + 'statuses' => PrettyNumber::convert(Status::count()), + 'profiles' => PrettyNumber::convert(Profile::count()), + 'users' => PrettyNumber::convert(User::count()), + 'instances' => PrettyNumber::convert(Instance::count()), + ]; + }); + } + protected static function postsGraph() { $ttl = now()->addHours(12); diff --git a/resources/views/admin/home.blade.php b/resources/views/admin/home.blade.php index 693be5908..6ce8ffcc8 100644 --- a/resources/views/admin/home.blade.php +++ b/resources/views/admin/home.blade.php @@ -2,7 +2,7 @@ @section('section') -
Dashboard
- {{$data['statuses_monthly']}} - in last 30 days -
- {{$data['users_monthly']}} - in last 30 days -
- {{$data['reports_monthly']}} - in last 30 days -
- {{$data['contact_monthly']}} - in last 30 days -
@@ -102,79 +86,280 @@Failed Jobs (24h)
-{{$data['failedjobs']}}
-Remote Instances
-{{$data['instances']}}
-Photos Uploaded
-{{$data['media']}}
-Storage Used
-{{$data['storage']}} bytes
-Stats
++ {{$data['statuses_monthly']}} + in last 30 days +
++ {{$data['users_monthly']}} + in last 30 days +
++ {{$data['reports_monthly']}} + in last 30 days +
++ {{$data['contact_monthly']}} + in last 30 days +
+Failed Jobs (24h)
+{{$data['failedjobs']}}
+Remote Instances
+{{$data['instances']}}
+Photos Uploaded
+{{$data['media']}}
+Storage Used
+{{$data['storage']}} bytes
+