1+ import { unstable_cache } from "next/cache" ;
12import { redirect } from "next/navigation" ;
23import { PublicMediaHub } from "@/components/media-hub/public-media-hub" ;
34import type { Locale } from "@/lib/i18n" ;
@@ -17,9 +18,63 @@ import {
1718
1819export const dynamic = "force-dynamic" ;
1920
21+ const MEDIA_HUB_LIVE_CACHE_SECONDS = 60 * 60 ;
22+ const MEDIA_HUB_REPORT_CACHE_SECONDS = 12 * 60 * 60 ;
23+ const MEDIA_HUB_ARCHIVE_CACHE_SECONDS = 12 * 60 * 60 ;
24+
25+ const getCachedSpikeMediaHubLiveWindows = unstable_cache (
26+ async ( locale : Locale ) => getSpikeMediaHubLiveWindows ( locale ) ,
27+ [ "spike-media-hub-live-windows" ] ,
28+ {
29+ revalidate : MEDIA_HUB_LIVE_CACHE_SECONDS ,
30+ tags : [ "spike-media-hub-live" ] ,
31+ } ,
32+ ) ;
33+
34+ const getCachedSpikePublishedSummary = unstable_cache (
35+ async (
36+ kind : Exclude < MediaHubPublicationKind , "none" > | undefined ,
37+ locale : Locale ,
38+ periodEndDate : string | undefined ,
39+ ) =>
40+ getLatestPublishedMediaHubReportSummary ( {
41+ kind,
42+ locale,
43+ periodEndDate,
44+ tenantId : "spike-ua" ,
45+ } ) ,
46+ [ "spike-media-hub-published-summary" ] ,
47+ {
48+ revalidate : MEDIA_HUB_REPORT_CACHE_SECONDS ,
49+ tags : [ "media-hub-report-summary" ] ,
50+ } ,
51+ ) ;
52+
53+ const getCachedSpikeReportArchive = unstable_cache (
54+ async (
55+ date : string | undefined ,
56+ kind : Exclude < MediaHubPublicationKind , "none" > | undefined ,
57+ locale : Locale ,
58+ query : string | undefined ,
59+ ) =>
60+ getMediaHubReportArchive ( {
61+ date,
62+ kind,
63+ locale,
64+ query,
65+ tenantId : "spike-ua" ,
66+ limit : 24 ,
67+ } ) ,
68+ [ "spike-media-hub-report-archive" ] ,
69+ {
70+ revalidate : MEDIA_HUB_ARCHIVE_CACHE_SECONDS ,
71+ tags : [ "media-hub-report-archive" ] ,
72+ } ,
73+ ) ;
74+
2075type MediaHubPageProps = {
2176 params : Promise < { locale : Locale } > ;
22- searchParams : Promise < { date ?: string ; kind ?: string ; q ?: string ; window ?: string } > ;
77+ searchParams : Promise < { archive ?: string ; date ?: string ; kind ?: string ; q ?: string ; window ?: string } > ;
2378} ;
2479
2580export default async function MediaHubPage ( {
@@ -38,21 +93,13 @@ export default async function MediaHubPage({
3893 const requestedDate = normalizeDate ( search . date ) ;
3994 const requestedQuery = normalizeQuery ( search . q ) ;
4095 const summaryKind = requestedKind ?? ( requestedWindow ? windowToKind ( requestedWindow ) : undefined ) ;
96+ const shouldLoadArchive = search . archive === "1" || Boolean ( requestedDate || requestedKind || requestedQuery ) ;
4197 const [ liveWindows , publishedSummary , archive ] = await Promise . all ( [
42- getSpikeMediaHubLiveWindows ( locale ) ,
43- getLatestPublishedMediaHubReportSummary ( {
44- kind : summaryKind ,
45- locale,
46- periodEndDate : requestedDate ,
47- tenantId : "spike-ua" ,
48- } ) ,
49- getMediaHubReportArchive ( {
50- date : requestedDate ,
51- kind : summaryKind ,
52- locale,
53- query : requestedQuery ,
54- tenantId : "spike-ua" ,
55- } ) ,
98+ getCachedSpikeMediaHubLiveWindows ( locale ) ,
99+ getCachedSpikePublishedSummary ( summaryKind , locale , requestedDate ) ,
100+ shouldLoadArchive
101+ ? getCachedSpikeReportArchive ( requestedDate , summaryKind , locale , requestedQuery )
102+ : Promise . resolve ( [ ] ) ,
56103 ] ) ;
57104 const selectedWindow = requestedWindow
58105 ? requestedWindow
@@ -75,10 +122,12 @@ export default async function MediaHubPage({
75122 archiveQuery = { {
76123 date : requestedDate ,
77124 kind : requestedKind ,
125+ loaded : shouldLoadArchive ,
78126 q : requestedQuery ,
79127 } }
80128 archiveHref = { ( filter ) => {
81129 const params = new URLSearchParams ( ) ;
130+ params . set ( "archive" , "1" ) ;
82131 if ( filter . kind ) params . set ( "kind" , filter . kind ) ;
83132 if ( filter . date ) params . set ( "date" , filter . date ) ;
84133 if ( filter . q ) params . set ( "q" , filter . q ) ;
0 commit comments