Skip to content

Commit 9846e7e

Browse files
committed
cache.putを忘れていた
1 parent 2d4f7ae commit 9846e7e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

app/lib/chatHistory.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export async function getChatOne(chatId: string, context: Context) {
215215
throw new Error("Not authenticated");
216216
}
217217

218-
return (await drizzle.query.chat.findFirst({
218+
const chatData = (await drizzle.query.chat.findFirst({
219219
where: and(eq(chat.chatId, chatId), eq(chat.userId, userId)),
220220
with: {
221221
section: true,
@@ -227,6 +227,18 @@ export async function getChatOne(chatId: string, context: Context) {
227227
},
228228
},
229229
})) as ChatWithMessages | undefined;
230+
231+
if (isCloudflare()) {
232+
const cache = await caches.open("chatHistory");
233+
await cache.put(
234+
cacheKeyForChat(chatId),
235+
new Response(JSON.stringify(chatData), {
236+
headers: { "Cache-Control": "max-age=86400, s-maxage=86400" },
237+
})
238+
);
239+
}
240+
241+
return chatData;
230242
}
231243

232244
export async function migrateChatUser(oldUserId: string, newUserId: string) {

0 commit comments

Comments
 (0)