Optimierung 3.4: Performance (Logging terminable, Single-Purchase memoisiert)

- LogApiUsage als terminable Middleware: der ApiUsageLog-INSERT laeuft nach
  gesendeter Antwort und verlaengert nicht mehr die Request-Dauer. Startzeit
  wird ueber ein Request-Attribut uebergeben (terminate() laeuft auf frischer
  Instanz).
- User::openSinglePurchaseCount() memoisiert die offenen Einmalkaeufe pro
  Request. Vorher wurde derselbe grantingSubmission-Count im Status-Widget
  mehrfach (Quota-Total, Quota-Remaining, openSinglePurchases) plus ein
  exists() in hasActiveBooking abgesetzt -> jetzt eine Query.
- CustomerCompanyContext::selectedCompany() nutzt eine einzige first()-Query
  statt exists()+first(); das Verwerfen nicht (mehr) erreichbarer Auswahlen
  bleibt erhalten.
- LegacySubscriptionService::cancelBundleFor() ist ein einziges Bulk-Update
  statt Update-pro-Iteration (UserPaymentOption hat keine Observer/Events).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 11:05:07 +00:00
parent f2c349ac2c
commit 9ed429fe74
6 changed files with 56 additions and 19 deletions

View file

@ -130,6 +130,8 @@ class User extends Authenticatable implements MustVerifyEmail
private ?bool $cachedHasUnlimitedQuota = null;
private ?int $cachedOpenSinglePurchaseCount = null;
/**
* Der Tarif des aktiven Stripe-Abos, aufgelöst über die in `plans`
* gepflegten Stripe-Preis-IDs. Null ohne (gültiges) Abo.
@ -216,7 +218,23 @@ class User extends Authenticatable implements MustVerifyEmail
($this->currentPlan()?->press_release_quota ?? 0) - (int) $this->press_release_quota_used_this_month,
);
return $planRemaining + $this->singlePurchases()->grantingSubmission()->count();
return $planRemaining + $this->openSinglePurchaseCount();
}
/**
* Bezahlte, noch nicht eingelöste Einmalkäufe (Einzel-/Extra-PM), die zur
* Einreichung berechtigen. Per-Request memoisiert, weil das Status-Widget
* den Wert je Render mehrfach abfragt (Kontingent, Buchungslabel, Gate).
*/
public function openSinglePurchaseCount(): int
{
if ($this->cachedOpenSinglePurchaseCount !== null) {
return $this->cachedOpenSinglePurchaseCount;
}
return $this->cachedOpenSinglePurchaseCount = $this->singlePurchases()
->grantingSubmission()
->count();
}
/**
@ -230,7 +248,7 @@ class User extends Authenticatable implements MustVerifyEmail
}
return ($this->currentPlan()?->press_release_quota ?? 0)
+ $this->singlePurchases()->grantingSubmission()->count();
+ $this->openSinglePurchaseCount();
}
/**
@ -253,7 +271,7 @@ class User extends Authenticatable implements MustVerifyEmail
return true;
}
if ($this->singlePurchases()->grantingSubmission()->exists()) {
if ($this->openSinglePurchaseCount() > 0) {
return true;
}