Optimierung 5.1: Tabellen-Concerns (Sortierung, Volltext-Heuristik, Stats)
- 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>
This commit is contained in:
parent
8e0aedaf95
commit
a8958c176e
15 changed files with 111 additions and 145 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Services\Admin;
|
|||
use App\Enums\Portal;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Models\PressRelease;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AdminPerformanceCache
|
||||
|
|
@ -49,6 +50,29 @@ class AdminPerformanceCache
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktiv-/Inaktiv-Kennzahlen einer `is_active`-Tabelle in einer einzigen
|
||||
* Aggregat-Abfrage. Single Source of Truth für die identischen Stat-Blöcke
|
||||
* der Benutzer- und Firmen-Liste.
|
||||
*
|
||||
* @param Builder<covariant \Illuminate\Database\Eloquent\Model> $query
|
||||
* @return array{total: int, active: int, inactive: int}
|
||||
*/
|
||||
public function activeInactiveStats(Builder $query): array
|
||||
{
|
||||
$stats = $query->toBase()
|
||||
->selectRaw('COUNT(*) as total')
|
||||
->selectRaw('SUM(CASE WHEN is_active = ? THEN 1 ELSE 0 END) as active', [true])
|
||||
->selectRaw('SUM(CASE WHEN is_active = ? THEN 1 ELSE 0 END) as inactive', [false])
|
||||
->first();
|
||||
|
||||
return [
|
||||
'total' => (int) ($stats->total ?? 0),
|
||||
'active' => (int) ($stats->active ?? 0),
|
||||
'inactive' => (int) ($stats->inactive ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
public function pressReleaseReviewCount(): int
|
||||
{
|
||||
return (int) $this->remember(self::PressReleaseReviewCount, self::StatsTtl, function (): int {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue