Optimierung 2.5: Kontakt-Helfer + tagSuggestionsFor zentralisiert

Erkenntnis: Die Admin-Inline-Query (Contact::withoutGlobalScopes()->where
->orderBy) ist exakt der Contact::forCompany()-Scope -> alle vier
Kontakt-Helfer waren funktional identisch. companyContacts/companyContact/
defaultContactIdFor in neuen Concern InteractsWithPressReleaseContacts
(ueber forCompany) ausgelagert. tagSuggestionsFor() (4x identisch) in
InteractsWithPressReleaseTags verschoben. Ungenutzte Collection-Importe
in den Customer-Editoren entfernt; selectedCompany() bleibt je Kontext
(Admin: withoutGlobalScopes find; Customer: CustomerCompanyContext).

Tests: volle Suite gruen (794 passed, 1 skipped).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 08:59:38 +00:00
parent b41d34e39f
commit 8c53146548
6 changed files with 80 additions and 178 deletions

View file

@ -19,6 +19,7 @@ use Livewire\Attributes\Title;
use Livewire\Volt\Component;
new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class extends Component {
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
@ -209,50 +210,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
: null;
}
private function defaultContactIdFor(int $companyId): ?int
{
if ($companyId <= 0) {
return null;
}
return $this->companyContacts($companyId)->first()?->id;
}
/**
* @return Collection<int, Contact>
*/
private function companyContacts(int $companyId): Collection
{
return Contact::withoutGlobalScopes()
->where('company_id', $companyId)
->orderBy('last_name')
->orderBy('first_name')
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
}
private function companyContact(int $contactId, int $companyId): ?Contact
{
if ($contactId <= 0 || $companyId <= 0) {
return null;
}
return Contact::withoutGlobalScopes()->where('company_id', $companyId)->whereKey($contactId)->first();
}
/**
* @return list<string>
*/
private function tagSuggestionsFor(?Company $company): array
{
$defaults = [__('Mittelstand'), __('Unternehmen'), __('Eröffnung'), __('Innovation'), __('Nachhaltigkeit')];
if (!$company) {
return $defaults;
}
return array_values(array_unique(array_filter([$company->portal?->label(), $company->country_code === 'DE' ? __('Deutschland') : null, ...$defaults])));
}
private function categoryOptions(): Collection
{
return app(AdminPerformanceCache::class)->remember(AdminPerformanceCache::ActiveCategoryOptions, AdminPerformanceCache::OptionsTtl, fn() => Category::query()->with('translations')->where('is_active', true)->orderBy('id')->get());

View file

@ -24,6 +24,7 @@ use Livewire\Attributes\Title;
use Livewire\Volt\Component;
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component {
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
@ -398,50 +399,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
: null;
}
private function defaultContactIdFor(int $companyId): ?int
{
if ($companyId <= 0) {
return null;
}
return $this->companyContacts($companyId)->first()?->id;
}
/**
* @return Collection<int, Contact>
*/
private function companyContacts(int $companyId): Collection
{
return Contact::withoutGlobalScopes()
->where('company_id', $companyId)
->orderBy('last_name')
->orderBy('first_name')
->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']);
}
private function companyContact(int $contactId, int $companyId): ?Contact
{
if ($contactId <= 0 || $companyId <= 0) {
return null;
}
return Contact::withoutGlobalScopes()->where('company_id', $companyId)->whereKey($contactId)->first();
}
/**
* @return list<string>
*/
private function tagSuggestionsFor(?Company $company): array
{
$defaults = [__('Mittelstand'), __('Unternehmen'), __('Eröffnung'), __('Innovation'), __('Nachhaltigkeit')];
if (!$company) {
return $defaults;
}
return array_values(array_unique(array_filter([$company->portal?->label(), $company->country_code === 'DE' ? __('Deutschland') : null, ...$defaults])));
}
private function categoryOptions(): Collection
{
return app(AdminPerformanceCache::class)->remember(AdminPerformanceCache::ActiveCategoryOptions, AdminPerformanceCache::OptionsTtl, fn() => Category::query()->with('translations')->where('is_active', true)->orderBy('id')->get());