Fix user count

This commit is contained in:
DariusIII
2026-04-28 10:52:03 +02:00
parent 9e86f97824
commit 4d5591a7c6
2 changed files with 30 additions and 2 deletions
@@ -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,
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\TestCase;
class AdminDashboardUserCountTest extends TestCase
{
public function test_dashboard_snapshot_excludes_soft_deleted_users_from_active_count(): void
{
$servicePath = app_path('Services/AdminDashboardSnapshotService.php');
$this->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);
}
}