diff --git a/apps/firehose-service/src/lib/cache-writer.ts b/apps/firehose-service/src/lib/cache-writer.ts index 0248578..4c16abb 100644 --- a/apps/firehose-service/src/lib/cache-writer.ts +++ b/apps/firehose-service/src/lib/cache-writer.ts @@ -443,12 +443,15 @@ export async function handleSiteCreateOrUpdate( options?: { forceRewriteHtml?: boolean; skipInvalidation?: boolean; + forceDownload?: boolean; } ): Promise { const forceRewriteHtml = options?.forceRewriteHtml === true; + const forceDownload = options?.forceDownload === true; logger.info(`Processing site ${did}/${rkey}`, { recordCid, forceRewriteHtml, + forceDownload, }); if (!record.root?.entries) { @@ -504,7 +507,7 @@ export async function handleSiteCreateOrUpdate( // Find new or changed files for (const file of newFiles) { const shouldForceRewrite = forceRewriteHtml && isHtmlFile(file.path); - if (oldFileCids[file.path] !== file.cid || shouldForceRewrite) { + if (forceDownload || oldFileCids[file.path] !== file.cid || shouldForceRewrite) { filesToDownload.push(file); } } @@ -552,7 +555,9 @@ export async function handleSiteCreateOrUpdate( // Backfill settings if a record exists for this rkey const settingsRecord = await fetchSettingsRecord(did, rkey, pdsEndpoint); if (settingsRecord) { - await handleSettingsUpdate(did, rkey, settingsRecord.record, settingsRecord.cid); + await handleSettingsUpdate(did, rkey, settingsRecord.record, settingsRecord.cid, { + skipInvalidation: options?.skipInvalidation, + }); } // Notify hosting-service to invalidate its local caches @@ -590,7 +595,13 @@ export async function handleSiteDelete(did: string, rkey: string): Promise /** * Handle settings create/update event */ -export async function handleSettingsUpdate(did: string, rkey: string, settings: WispSettings, recordCid: string): Promise { +export async function handleSettingsUpdate( + did: string, + rkey: string, + settings: WispSettings, + recordCid: string, + options?: { skipInvalidation?: boolean } +): Promise { logger.info(`Updating settings for ${did}/${rkey}`); await upsertSiteSettingsCache(did, rkey, recordCid, { @@ -603,7 +614,9 @@ export async function handleSettingsUpdate(did: string, rkey: string, settings: }); // Notify hosting-service to invalidate its local caches (redirect rules depend on settings) - await publishCacheInvalidation(did, rkey, 'settings'); + if (!options?.skipInvalidation) { + await publishCacheInvalidation(did, rkey, 'settings'); + } } /** diff --git a/apps/firehose-service/src/lib/revalidate-worker.ts b/apps/firehose-service/src/lib/revalidate-worker.ts index 4c1d081..1746e8d 100644 --- a/apps/firehose-service/src/lib/revalidate-worker.ts +++ b/apps/firehose-service/src/lib/revalidate-worker.ts @@ -49,8 +49,12 @@ async function processMessage(id: string, rawFields: string[]): Promise { return; } + // For storage-miss events, force re-download all files since storage is empty + const forceDownload = reason.startsWith('storage-miss'); + await handleSiteCreateOrUpdate(did, rkey, record.record, record.cid, { skipInvalidation: true, + forceDownload, }); logger.info(`[Revalidate] Completed ${id}: ${did}/${rkey}`); diff --git a/apps/hosting-service/src/lib/file-serving.ts b/apps/hosting-service/src/lib/file-serving.ts index cea896e..9b417e8 100644 --- a/apps/hosting-service/src/lib/file-serving.ts +++ b/apps/hosting-service/src/lib/file-serving.ts @@ -32,11 +32,7 @@ async function getFileWithMetadata(did: string, rkey: string, filePath: string) const result = await storage.getWithMetadata(key); if (result) { - const metadata = result.metadata; - const tier = - metadata && typeof metadata === 'object' && 'tier' in metadata - ? String((metadata as Record).tier) - : 'unknown'; + const tier = result.source || 'unknown'; const size = result.data ? (result.data as Uint8Array).length : 0; console.log(`[Storage] Served ${filePath} from ${tier} tier (${size} bytes) - ${did}:${rkey}`); }