2929use App \Services \AccountSuggestionService ;
3030use App \Services \AdminAuditLogService ;
3131use App \Services \ExploreService ;
32+ use App \Services \InstanceService ;
3233use App \Services \NodeinfoCrawlerService ;
3334use App \Services \SanitizeService ;
3435use App \Services \VersionCheckService ;
@@ -881,6 +882,7 @@ public function updateInstanceSettings(Request $request, $id)
881882 $ instance ->update ($ validated );
882883
883884 app (AdminAuditLogService::class)->logInstanceUpdateSettings ($ request ->user (), $ instance , ['old ' => $ oldValues , 'new ' => $ validated ]);
885+ app (InstanceService::class)->flushStats ();
884886
885887 return $ this ->success ();
886888 }
@@ -898,6 +900,7 @@ public function updateInstanceRefreshData(Request $request, $id)
898900 $ instance ->save ();
899901
900902 FetchInstanceNodeinfo::dispatch ($ instance )->onQueue ('actor-update ' );
903+ app (InstanceService::class)->flushStats ();
901904
902905 return $ this ->success ();
903906 }
@@ -911,6 +914,7 @@ public function instanceActivate(Request $request, $id)
911914
912915 app (AdminAuditLogService::class)->logInstanceActivated ($ request ->user (), $ instance );
913916 app (SanitizeService::class)->getBannedDomains (true );
917+ app (InstanceService::class)->flushStats ();
914918
915919 return $ this ->success ();
916920 }
@@ -924,79 +928,23 @@ public function instanceSuspend(Request $request, $id)
924928
925929 app (AdminAuditLogService::class)->logInstanceSuspended ($ request ->user (), $ instance );
926930 app (SanitizeService::class)->getBannedDomains (true );
931+ app (InstanceService::class)->flushStats ();
927932
928933 return $ this ->success ();
929934 }
930935
931936 public function instanceStats (Request $ request )
932937 {
933- $ res = Cache::remember ('loops:admin:api:instance-stats ' , now ()->addHours (4 ), function () {
934- return [
935- [
936- 'name ' => 'Total ' ,
937- 'value ' => Instance::active ()->count (),
938- ],
939- [
940- 'name ' => 'New ' ,
941- 'value ' => Instance::active ()->where ('created_at ' , '> ' , now ()->subHours (24 ))->count (),
942- ],
943- [
944- 'name ' => 'Blocked ' ,
945- 'value ' => Instance::whereFederationState (2 )->count (),
946- ],
947- [
948- 'name ' => 'Users ' ,
949- 'value ' => Instance::active ()->sum ('user_count ' ),
950- ],
951- [
952- 'name ' => 'Videos ' ,
953- 'value ' => Instance::active ()->sum ('video_count ' ),
954- ],
955- [
956- 'name ' => 'Followers ' ,
957- 'value ' => Instance::active ()->sum ('follower_count ' ),
958- ],
959- [
960- 'name ' => 'Following ' ,
961- 'value ' => Instance::active ()->sum ('following_count ' ),
962- ],
963- [
964- 'name ' => 'Comments ' ,
965- 'value ' => Instance::active ()->sum ('comment_count ' ),
966- ],
967- ];
968- });
938+ $ res = app (InstanceService::class)->getStats ();
969939
970940 return $ this ->data ($ res );
971941 }
972942
973943 public function instanceAdvancedStats ()
974944 {
975- $ totalInstances = Instance::active ()->count ();
976- $ activeInstances = Instance::active ()->count ();
977- $ allowedVideoPosts = Instance::active ()->where ('allow_video_posts ' , true )->count ();
978- $ allowedInFyf = Instance::active ()->where ('allow_videos_in_fyf ' , true )->count ();
979-
980- $ softwareStats = Instance::select ('software ' )
981- ->selectRaw ('COUNT(*) as count ' )
982- ->selectRaw ('SUM(CASE WHEN allow_video_posts = 1 THEN 1 ELSE 0 END) as allow_video_posts_count ' )
983- ->where ('is_blocked ' , false )
984- ->active ()
985- ->groupBy ('software ' )
986- ->orderByDesc ('count ' )
987- ->get ();
945+ $ res = app (InstanceService::class)->getAdvancedStats ();
988946
989- return response ()->json ([
990- 'data ' => [
991- 'stats ' => [
992- ['name ' => 'Total Instances ' , 'value ' => $ totalInstances ],
993- ['name ' => 'Active Instances ' , 'value ' => $ activeInstances ],
994- ['name ' => 'Video Posts Allowed ' , 'value ' => $ allowedVideoPosts ],
995- ['name ' => 'FYF Allowed ' , 'value ' => $ allowedInFyf ],
996- ],
997- 'software_stats ' => $ softwareStats ,
998- ],
999- ]);
947+ return response ()->json ($ res );
1000948 }
1001949
1002950 public function manageInstanceToggleBySoftware (Request $ request )
@@ -1012,6 +960,7 @@ public function manageInstanceToggleBySoftware(Request $request)
1012960 ->update (['allow_video_posts ' => $ request ->allow_video_posts ]);
1013961
1014962 app (AdminAuditLogService::class)->logInstanceSoftwareUpdateAllowVideoPosts ($ request ->user (), ['software ' => $ software , 'allow_video_posts ' => $ allowVideoPosts ]);
963+ app (InstanceService::class)->flushStats ();
1015964
1016965 return response ()->json ([
1017966 'data ' => [
@@ -1036,6 +985,7 @@ public function manageInstanceToggleByDomains(Request $request)
1036985 ->update (['allow_video_posts ' => $ request ->allow_video_posts ]);
1037986
1038987 app (AdminAuditLogService::class)->logInstanceDomainsUpdateAllowVideoPosts ($ request ->user (), ['domains ' => $ domains , 'allow_video_posts ' => $ request ->allow_video_posts ]);
988+ app (InstanceService::class)->flushStats ();
1039989
1040990 return response ()->json ([
1041991 'data ' => [
@@ -1082,6 +1032,7 @@ public function instanceCreate(Request $request)
10821032
10831033 app (AdminAuditLogService::class)->logInstanceDomainAdded ($ request ->user (), $ instance );
10841034 app (SanitizeService::class)->getBannedDomains (true );
1035+ app (InstanceService::class)->flushStats ();
10851036
10861037 return $ this ->success ();
10871038 }
0 commit comments