[READ-ONLY] Mirror of https://github.com/flo-bit/atmo-garden. atmo.garden
0

Configure Feed

Select the types of activity you want to include in your feed.

refresh cache

+46 -27
+37 -26
src/lib/reddit/bot.ts
··· 291 291 // Loading a client for a stored community 292 292 // ------------------------------------------------------------------------- 293 293 294 + /** 295 + * Re-read the community's on-network profile (via the public appview) + 296 + * `garden.atmo.community/self` record and write the fresh values into 297 + * the D1 cache. Used by the cron tick AND by the editCommunity remote so 298 + * an edit takes effect immediately instead of waiting up to a minute for 299 + * the next cron. Fails soft — errors just leave the cache stale until 300 + * the next cron tick catches up. 301 + */ 302 + export async function refreshCommunityCache( 303 + env: App.Platform['env'], 304 + row: CommunityRow 305 + ): Promise<void> { 306 + const appview = new Client({ 307 + handler: simpleFetchHandler({ service: PUBLIC_APPVIEW }) 308 + }); 309 + try { 310 + const [profile, config] = await Promise.all([ 311 + appview.get('app.bsky.actor.getProfile', { params: { actor: row.did } }), 312 + fetchCommunityConfig(row.pds, row.did) 313 + ]); 314 + if (profile.ok) { 315 + await updateCommunityProfile(env.DB, row.did, { 316 + display_name: profile.data.displayName ?? null, 317 + avatar: profile.data.avatar ?? null, 318 + description: stripCommunityLink(profile.data.description), 319 + accent_color: config.accentColor, 320 + followers_count: profile.data.followersCount ?? 0 321 + }); 322 + } 323 + } catch (e) { 324 + console.error('[refreshCommunityCache] failed', e); 325 + } 326 + } 327 + 294 328 async function loadClient( 295 329 env: App.Platform['env'], 296 330 row: CommunityRow ··· 1258 1292 const errors: string[] = []; 1259 1293 const communities = await listCommunities(db); 1260 1294 1261 - const appview = new Client({ 1262 - handler: simpleFetchHandler({ service: PUBLIC_APPVIEW }) 1263 - }); 1264 - 1265 1295 let postsCreated = 0; 1266 1296 for (const row of communities) { 1267 1297 try { ··· 1272 1302 } 1273 1303 1274 1304 // Best-effort: refresh cached profile metadata (avatar, display name, 1275 - // desc, follower count) from the appview, and the accent color from 1276 - // the community's `garden.atmo.community/self` record on the PDS. 1277 - // Both requests run in parallel since they hit different services. 1278 - // `followersCount` already comes back on every getProfile call, so 1279 - // caching it is free — no separate refresh schedule needed. 1280 - try { 1281 - const [profile, config] = await Promise.all([ 1282 - appview.get('app.bsky.actor.getProfile', { params: { actor: row.did } }), 1283 - fetchCommunityConfig(row.pds, row.did) 1284 - ]); 1285 - if (profile.ok) { 1286 - await updateCommunityProfile(db, row.did, { 1287 - display_name: profile.data.displayName ?? null, 1288 - avatar: profile.data.avatar ?? null, 1289 - description: stripCommunityLink(profile.data.description), 1290 - accent_color: config.accentColor, 1291 - followers_count: profile.data.followersCount ?? 0 1292 - }); 1293 - } 1294 - } catch { 1295 - // non-fatal 1296 - } 1305 + // desc, follower count) from the appview + accent color from the 1306 + // community's `garden.atmo.community/self` record. 1307 + await refreshCommunityCache(env, row); 1297 1308 } 1298 1309 1299 1310 // Drain the jetstream for `garden.atmo.submission` records created via the
+9 -1
src/lib/reddit/server/communities.remote.ts
··· 15 15 registerCommunity, 16 16 updateCommunity, 17 17 fetchCommunityConfig, 18 - checkCanSubmit 18 + checkCanSubmit, 19 + refreshCommunityCache 19 20 } from '../bot'; 20 21 import { parseListUri } from '../list-uri'; 21 22 import { ··· 325 326 console.error('[editCommunity]', e); 326 327 error(400, `Update failed: ${msg}`); 327 328 } 329 + 330 + // Force-refresh the D1 cache so the caller's next page load already 331 + // shows the new avatar/description/accent color, instead of waiting 332 + // up to a minute for the next cron tick. Soft-failure: if the 333 + // appview hasn't seen the change yet (PDS → relay → appview lag), 334 + // the cache stays briefly stale and the cron picks it up next tick. 335 + await refreshCommunityCache(env, row); 328 336 329 337 return { ok: true, did: row.did, handle: row.handle }; 330 338 }