- HasSortableTable::sort() ersetzt 5 byte-identische sort()-Kopien in den Admin-Listen (Benutzer, Firmen, Kategorien, Kontakte, Pressemitteilungen). $sortBy/$sortDir-Defaults bleiben je Komponente, da sie divergieren. - HasFullTextSearch::supportsFullTextSearch() ersetzt 9 byte-identische Kopien (4 Index-Listen + 5 Firmen-Comboboxen); ungenutzte DB-Imports entfernt. - AdminPerformanceCache::activeInactiveStats(Builder) buendelt den identischen SUM(CASE WHEN is_active)-Block der Benutzer- und Firmenliste. Zurueckgestellt (real divergent): HasResettableFilters (updatedXxxFilter normalisieren teils zusaetzlich) und eine gemeinsame hydrateRelationCounts(). Tests: erweiterte AdminPerformanceCacheTest; 99 Admin-Tests bleiben gruen. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Models\Company;
|
|
use App\Services\Admin\AdminPerformanceCache;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
test('activeInactiveStats aggregates total, active and inactive in one shape', function () {
|
|
Company::factory()->count(2)->create(['is_active' => true]);
|
|
Company::factory()->create(['is_active' => false]);
|
|
|
|
$stats = app(AdminPerformanceCache::class)->activeInactiveStats(Company::query());
|
|
|
|
expect($stats)->toBe([
|
|
'total' => 3,
|
|
'active' => 2,
|
|
'inactive' => 1,
|
|
]);
|
|
});
|
|
|
|
test('admin performance cache is flushed when observed models change', function () {
|
|
Cache::put(AdminPerformanceCache::DashboardStats, ['stale' => true], 600);
|
|
Cache::put(AdminPerformanceCache::PressReleaseStats, ['stale' => true], 600);
|
|
Cache::put(AdminPerformanceCache::RoleOptions, ['stale' => true], 600);
|
|
|
|
Company::factory()->create();
|
|
|
|
expect(Cache::has(AdminPerformanceCache::DashboardStats))->toBeFalse()
|
|
->and(Cache::has(AdminPerformanceCache::PressReleaseStats))->toBeFalse()
|
|
->and(Cache::has(AdminPerformanceCache::RoleOptions))->toBeFalse();
|
|
});
|
|
|
|
test('admin role option cache is flushed when roles change', function () {
|
|
Cache::put(AdminPerformanceCache::RoleOptions, ['stale' => true], 600);
|
|
|
|
Role::query()->create([
|
|
'name' => 'temporary-admin-role',
|
|
'guard_name' => 'web',
|
|
]);
|
|
|
|
expect(Cache::has(AdminPerformanceCache::RoleOptions))->toBeFalse();
|
|
});
|