Boost-Buchung invalidiert gecachte Start- und Branchenseiten sofort
Statt bis zu 300 s Cache-TTL zu warten, verwirft der BoostService nach der Buchung die Home-/Kategorie-Caches der betroffenen Ausgaben (inkl. Eltern-Rubrik) — die bezahlte Platzierung ist direkt sichtbar. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
6e1267f00f
commit
9d6ef50e62
2 changed files with 65 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Services\PressRelease;
|
||||
|
||||
use App\Enums\Portal;
|
||||
use App\Enums\PressReleaseClassification;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Exceptions\BoostNotAllowedException;
|
||||
|
|
@ -11,6 +12,7 @@ use App\Models\User;
|
|||
use App\Services\Billing\CreditPricingService;
|
||||
use App\Services\Billing\CreditWalletService;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +65,7 @@ class BoostService
|
|||
|
||||
$credits = $this->pricing->boostCredits($days);
|
||||
|
||||
return DB::transaction(function () use ($user, $pressRelease, $days, $credits): Boost {
|
||||
$boost = DB::transaction(function () use ($user, $pressRelease, $days, $credits): Boost {
|
||||
$startsAt = $this->activeUntil($pressRelease) ?? now();
|
||||
|
||||
$boost = $pressRelease->boosts()->create([
|
||||
|
|
@ -83,5 +85,39 @@ class BoostService
|
|||
|
||||
return $boost;
|
||||
});
|
||||
|
||||
$this->forgetPlacementCaches($pressRelease);
|
||||
|
||||
return $boost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gecachte Start-/Branchenseiten der betroffenen Ausgaben verwerfen,
|
||||
* damit die bezahlte Platzierung sofort sichtbar wird statt erst nach
|
||||
* Ablauf der Cache-TTL (HomePageData/CategoryPageData, 300 s).
|
||||
*/
|
||||
private function forgetPlacementCaches(PressRelease $pressRelease): void
|
||||
{
|
||||
$portals = $pressRelease->portal === Portal::Both
|
||||
? [Portal::Presseecho->value, Portal::Businessportal24->value]
|
||||
: [$pressRelease->portal->value];
|
||||
|
||||
// Branchenseite der eigenen Rubrik plus Eltern-Rubrik (deren Seite
|
||||
// schließt Unterkategorien mit ein), je hinterlegter Sprache.
|
||||
$category = $pressRelease->category()
|
||||
->with(['translations', 'parent.translations'])
|
||||
->first();
|
||||
$translations = collect($category?->translations ?? [])
|
||||
->merge($category?->parent?->translations ?? []);
|
||||
|
||||
foreach ($portals as $portal) {
|
||||
Cache::forget(sprintf('web.home.%s.%s', $portal, $pressRelease->language));
|
||||
|
||||
foreach ($translations as $translation) {
|
||||
if (filled($translation->slug)) {
|
||||
Cache::forget(sprintf('web.category.%s.%s.%s', $portal, $translation->locale, $translation->slug));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue