Add homepage announcement module
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Services;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Leaderboard;
|
||||
use App\Models\Tag;
|
||||
use App\Services\HomepageAnnouncementService;
|
||||
use App\Services\ArtworkSearchService;
|
||||
use App\Services\EarlyGrowth\EarlyGrowth;
|
||||
use App\Services\EarlyGrowth\GridFiller;
|
||||
@@ -57,6 +58,7 @@ final class HomepageService
|
||||
private readonly GroupDiscoveryService $groupDiscovery,
|
||||
private readonly LeaderboardService $leaderboards,
|
||||
private readonly WorldService $worlds,
|
||||
private readonly HomepageAnnouncementService $homepageAnnouncements,
|
||||
) {}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
@@ -68,9 +70,17 @@ final class HomepageService
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->guestPayloadCache()->remember(
|
||||
// Use a stale-while-revalidate pattern: serve fresh cache for a short
|
||||
// period and allow serving stale data while the cache is recalculated
|
||||
// in the background. This reduces latency for the homepage on cache
|
||||
// miss/expiration and keeps the heavy aggregation from blocking
|
||||
// responses.
|
||||
$ttl = $this->guestPayloadCacheTtl();
|
||||
$freshSeconds = min(30, max(5, (int) config('homepage.fresh_seconds', 30)));
|
||||
|
||||
return $this->guestPayloadCache()->flexible(
|
||||
$this->guestPayloadCacheKey(),
|
||||
$this->guestPayloadCacheTtl(),
|
||||
[$freshSeconds, $ttl],
|
||||
fn (): array => $this->buildGuestPayload(),
|
||||
);
|
||||
}
|
||||
@@ -119,6 +129,7 @@ final class HomepageService
|
||||
{
|
||||
return [
|
||||
'hero' => $this->getHeroArtwork(),
|
||||
'announcement' => $this->homepageAnnouncements->toHomepagePayload($this->homepageAnnouncements->getActiveForHomepage()),
|
||||
'community_favorites' => $this->getCommunityFavorites(),
|
||||
'hall_of_fame' => $this->getHallOfFame(),
|
||||
'rising' => $this->getRising(),
|
||||
@@ -171,6 +182,7 @@ final class HomepageService
|
||||
'is_logged_in' => true,
|
||||
'user_data' => $this->getUserData($user),
|
||||
'hero' => $this->getHeroArtwork(),
|
||||
'announcement' => $this->homepageAnnouncements->toHomepagePayload($this->homepageAnnouncements->getActiveForHomepage()),
|
||||
'community_favorites' => $this->getCommunityFavorites(),
|
||||
'hall_of_fame' => $this->getHallOfFame(),
|
||||
'for_you' => $this->getForYouPreview($user),
|
||||
|
||||
Reference in New Issue
Block a user