From 4d5591a7c695e8d2e18bcb6a094083bef3a7ef6e Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 28 Apr 2026 10:52:03 +0200 Subject: [PATCH] Fix user count --- .../AdminDashboardSnapshotService.php | 5 ++-- tests/Feature/AdminDashboardUserCountTest.php | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/AdminDashboardUserCountTest.php diff --git a/app/Services/AdminDashboardSnapshotService.php b/app/Services/AdminDashboardSnapshotService.php index 96e598de2..94601fb4e 100644 --- a/app/Services/AdminDashboardSnapshotService.php +++ b/app/Services/AdminDashboardSnapshotService.php @@ -100,7 +100,7 @@ class AdminDashboardSnapshotService // Approximate counts on huge tables — InnoDB metadata estimates are // good enough for the admin overview tiles. $releasesCount = ApproximateRowCount::for('releases'); - $usersCount = ApproximateRowCount::for('users'); + $usersApproximateCount = ApproximateRowCount::for('users'); $groupsCount = ApproximateRowCount::for('usenet_groups'); $failedCount = ApproximateRowCount::for('dnzb_failures'); @@ -108,6 +108,7 @@ class AdminDashboardSnapshotService $activeGroupsCount = UsenetGroup::where('active', 1)->count(); $reportedCount = ReleaseReport::where('status', 'pending')->count(); $softDeletedCount = User::onlyTrashed()->count(); + $activeUsersCount = max($usersApproximateCount - $softDeletedCount, 0); // Replaces previous whereJsonContains() count which couldn't use an index. $permanentlyDeletedCount = UserActivity::query() @@ -121,7 +122,7 @@ class AdminDashboardSnapshotService return [ 'releases' => $releasesCount, 'releases_today' => $releasesToday, - 'users' => $usersCount, + 'users' => $activeUsersCount, 'users_today' => $usersToday, 'groups' => $groupsCount, 'active_groups' => $activeGroupsCount, diff --git a/tests/Feature/AdminDashboardUserCountTest.php b/tests/Feature/AdminDashboardUserCountTest.php new file mode 100644 index 000000000..fc06c66f1 --- /dev/null +++ b/tests/Feature/AdminDashboardUserCountTest.php @@ -0,0 +1,27 @@ +assertFileExists($servicePath); + + $content = (string) file_get_contents($servicePath); + + $this->assertStringContainsString('$usersApproximateCount = ApproximateRowCount::for(\'users\');', $content); + $this->assertStringContainsString('$softDeletedCount = User::onlyTrashed()->count();', $content); + $this->assertStringContainsString('$activeUsersCount = max($usersApproximateCount - $softDeletedCount, 0);', $content); + $this->assertStringContainsString("'users' => \$activeUsersCount", $content); + } +} + + +