Skip to content

Commit 66c1a59

Browse files
committed
Refactor cache key generation for user summaries into a separate function to fix inconsistencies
1 parent 730be96 commit 66c1a59

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/aiAnalysis/createAISummary.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export async function createResponse (opts: { conversationId?: string; postId?:
5858
}
5959
}
6060

61+
function getCacheKeyForUserSummary (username: string) {
62+
return `aiSummary:${username}`;
63+
}
64+
6165
export async function generateOpenAISummary (event: ScheduledJobEvent<JSONObject | undefined>, context: JobContext) {
6266
if (context.subredditName !== CONTROL_SUBREDDIT) {
6367
console.error(`generateOpenAISummary should only run on subreddit ${CONTROL_SUBREDDIT}, but is running on ${context.subredditName}`);
@@ -73,7 +77,7 @@ export async function generateOpenAISummary (event: ScheduledJobEvent<JSONObject
7377
return;
7478
}
7579

76-
const cacheKey = `aiSummary:${username}`;
80+
const cacheKey = getCacheKeyForUserSummary(username);
7781
const cachedSummary = await context.redis.get(cacheKey);
7882
if (cachedSummary) {
7983
console.log(`AI Summary: Using cached summary for user ${username}`);
@@ -256,7 +260,7 @@ export async function openAISummaryLookupAndRespond (event: ScheduledJobEvent<JS
256260
prompt,
257261
}, context);
258262

259-
const cacheKey = `cachedAISummary:${username}`;
263+
const cacheKey = getCacheKeyForUserSummary(username);
260264
await context.redis.set(cacheKey, result, { expiration: addDays(new Date(), 1) });
261265

262266
await createResponse({

0 commit comments

Comments
 (0)