Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place

write to sites table as well

+18 -1
+3 -1
apps/firehose-service/src/lib/cache-writer.ts
··· 13 13 import { MAX_BLOB_SIZE, MAX_FILE_COUNT, MAX_SITE_SIZE } from '@wispplace/constants'; 14 14 import { createLogger } from '@wispplace/observability'; 15 15 import { writeFile, deleteFile, listFiles } from './storage'; 16 - import { getSiteCache, upsertSiteCache, deleteSiteCache, upsertSiteSettingsCache, deleteSiteSettingsCache } from './db'; 16 + import { getSiteCache, upsertSiteCache, deleteSiteCache, upsertSiteSettingsCache, deleteSiteSettingsCache, upsertSite, deleteSite } from './db'; 17 17 import { rewriteHtmlPaths, isHtmlFile } from './html-rewriter'; 18 18 import { gunzipSync } from 'zlib'; 19 19 import { publishCacheInvalidation } from './cache-invalidation'; ··· 550 550 // Update DB with new CIDs 551 551 logger.debug(`About to upsert site cache for ${did}/${rkey}`); 552 552 await upsertSiteCache(did, rkey, recordCid, newFileCids); 553 + await upsertSite(did, rkey, record.site); 553 554 logger.debug(`Updated site cache for ${did}/${rkey} with record CID ${recordCid}`); 554 555 555 556 // Backfill settings if a record exists for this rkey ··· 585 586 586 587 // Delete from DB 587 588 await deleteSiteCache(did, rkey); 589 + await deleteSite(did, rkey); 588 590 589 591 // Notify hosting-service to invalidate its local caches 590 592 await publishCacheInvalidation(did, rkey, 'delete');
+15
apps/firehose-service/src/lib/db.ts
··· 147 147 await sql`DELETE FROM site_settings_cache WHERE did = ${did} AND rkey = ${rkey}`; 148 148 } 149 149 150 + export async function upsertSite(did: string, rkey: string, displayName: string): Promise<void> { 151 + await sql` 152 + INSERT INTO sites (did, rkey, display_name, created_at, updated_at) 153 + VALUES (${did}, ${rkey}, ${displayName}, EXTRACT(EPOCH FROM NOW()), EXTRACT(EPOCH FROM NOW())) 154 + ON CONFLICT (did, rkey) 155 + DO UPDATE SET 156 + display_name = EXCLUDED.display_name, 157 + updated_at = EXTRACT(EPOCH FROM NOW()) 158 + `; 159 + } 160 + 161 + export async function deleteSite(did: string, rkey: string): Promise<void> { 162 + await sql`DELETE FROM sites WHERE did = ${did} AND rkey = ${rkey}`; 163 + } 164 + 150 165 export async function closeDatabase(): Promise<void> { 151 166 await sql.end({ timeout: 5 }); 152 167 logger.info('[DB] Database connections closed');