An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: add versioning to chat storage keys
Yoshiki Miura2cca019b449d
diff --git a/lib/actions/chat.ts b/lib/actions/chat.tsindex 61dde6f6..3efa4033 100644--- a/lib/actions/chat.ts+++ b/lib/actions/chat.ts@@ -9,6 +9,11 @@ async function getRedis(): Promise<RedisWrapper> {return await getRedisClient()}+const CHAT_VERSION = 'v2'+function getUserChatKey(userId: string) {+ return `user:${CHAT_VERSION}:chat:${userId}`+}+export async function getChats(userId?: string | null) {if (!userId) {return []@@ -16,7 +21,7 @@ export async function getChats(userId?: string | null) {try {const redis = await getRedis()- const chats = await redis.zrange(`user:chat:${userId}`, 0, -1, {+ const chats = await redis.zrange(getUserChatKey(userId), 0, -1, {rev: true})@@ -86,7 +91,8 @@ export async function clearChats(userId: string = 'anonymous'): Promise<{ error?: string }> {const redis = await getRedis()- const chats = await redis.zrange(`user:chat:${userId}`, 0, -1)+ const userChatKey = getUserChatKey(userId)+ const chats = await redis.zrange(userChatKey, 0, -1)if (!chats.length) {return { error: 'No chats to clear' }}@@ -94,7 +100,7 @@ export async function clearChats(for (const chat of chats) {pipeline.del(chat)- pipeline.zrem(`user:chat:${userId}`, chat)+ pipeline.zrem(userChatKey, chat)}await pipeline.exec()@@ -114,7 +120,7 @@ export async function saveChat(chat: Chat, userId: string = 'anonymous') {}pipeline.hmset(`chat:${chat.id}`, chatToSave)- pipeline.zadd(`user:chat:${userId}`, Date.now(), `chat:${chat.id}`)+ pipeline.zadd(getUserChatKey(userId), Date.now(), `chat:${chat.id}`)const results = await pipeline.exec()