18
18
Status ,
19
19
User
20
20
};
21
+ use App \Models \Conversation ;
22
+ use App \Models \RemoteReport ;
21
23
use App \Services \AccountService ;
22
24
use App \Services \AdminStatsService ;
23
25
use App \Services \ConfigCacheService ;
@@ -405,6 +407,9 @@ public function getUsers(Request $request)
405
407
{
406
408
abort_if (!$ request ->user (), 404 );
407
409
abort_unless ($ request ->user ()->is_admin == 1 , 404 );
410
+ $ this ->validate ($ request , [
411
+ 'sort ' => 'sometimes|in:asc,desc ' ,
412
+ ]);
408
413
$ q = $ request ->input ('q ' );
409
414
$ sort = $ request ->input ('sort ' , 'desc ' ) === 'asc ' ? 'asc ' : 'desc ' ;
410
415
$ res = User::whereNull ('status ' )
@@ -422,17 +427,29 @@ public function getUser(Request $request)
422
427
abort_unless ($ request ->user ()->is_admin == 1 , 404 );
423
428
424
429
$ id = $ request ->input ('user_id ' );
425
- $ user = User::findOrFail ($ id );
426
- $ profile = $ user ->profile ;
427
- $ account = AccountService::get ($ user ->profile_id , true );
428
- return (new AdminUser ($ user ))->additional (['meta ' => [
429
- 'account ' => $ account ,
430
- 'moderation ' => [
431
- 'unlisted ' => (bool ) $ profile ->unlisted ,
432
- 'cw ' => (bool ) $ profile ->cw ,
433
- 'no_autolink ' => (bool ) $ profile ->no_autolink
434
- ]
435
- ]]);
430
+ $ key = 'pf-admin-api:getUser:byId: ' . $ id ;
431
+ if ($ request ->has ('refresh ' )) {
432
+ Cache::forget ($ key );
433
+ }
434
+ return Cache::remember ($ key , 86400 , function () use ($ id ) {
435
+ $ user = User::findOrFail ($ id );
436
+ $ profile = $ user ->profile ;
437
+ $ account = AccountService::get ($ user ->profile_id , true );
438
+ $ res = (new AdminUser ($ user ))->additional (['meta ' => [
439
+ 'cached_at ' => str_replace ('+00:00 ' , 'Z ' , now ()->format (DATE_RFC3339_EXTENDED )),
440
+ 'account ' => $ account ,
441
+ 'dms_sent ' => Conversation::whereFromId ($ profile ->id )->count (),
442
+ 'report_count ' => Report::where ('object_id ' , $ profile ->id )->orWhere ('reported_profile_id ' , $ profile ->id )->count (),
443
+ 'remote_report_count ' => RemoteReport::whereAccountId ($ profile ->id )->count (),
444
+ 'moderation ' => [
445
+ 'unlisted ' => (bool ) $ profile ->unlisted ,
446
+ 'cw ' => (bool ) $ profile ->cw ,
447
+ 'no_autolink ' => (bool ) $ profile ->no_autolink
448
+ ]
449
+ ]]);
450
+
451
+ return $ res ;
452
+ });
436
453
}
437
454
438
455
public function userAdminAction (Request $ request )
0 commit comments