From f16a233559bf62df87e3f790d08d0dd6cfb6f1be Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Thu, 19 Dec 2024 21:17:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20perf:=20improve=20`get?= =?UTF-8?q?UserState`=20api=20performance=20(#5076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/server/models/message.ts | 10 ++++++++++ src/database/server/models/session.ts | 10 ++++++++++ src/server/routers/lambda/user.ts | 11 ++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/database/server/models/message.ts b/src/database/server/models/message.ts index 7fa7a477df22..543b71a742ce 100644 --- a/src/database/server/models/message.ts +++ b/src/database/server/models/message.ts @@ -294,6 +294,16 @@ export class MessageModel { return result[0].count; }; + hasMoreThanN = async (n: number): Promise => { + const result = await this.db + .select({ id: messages.id }) + .from(messages) + .where(eq(messages.userId, this.userId)) + .limit(n + 1); + + return result.length > n; + }; + // **************** Create *************** // create = async ( diff --git a/src/database/server/models/session.ts b/src/database/server/models/session.ts index 74a4ae87dc39..2a39ba4127bd 100644 --- a/src/database/server/models/session.ts +++ b/src/database/server/models/session.ts @@ -95,6 +95,16 @@ export class SessionModel { return result[0].count; }; + hasMoreThanN = async (n: number): Promise => { + const result = await this.db + .select({ id: sessions.id }) + .from(sessions) + .where(eq(sessions.userId, this.userId)) + .limit(n + 1); + + return result.length > n; + }; + // **************** Create *************** // create = async ({ diff --git a/src/server/routers/lambda/user.ts b/src/server/routers/lambda/user.ts index f7522004940b..6c8f6a19a794 100644 --- a/src/server/routers/lambda/user.ts +++ b/src/server/routers/lambda/user.ts @@ -58,16 +58,17 @@ export const userRouter = router({ } const messageModel = new MessageModel(serverDB, ctx.userId); - const messageCount = await messageModel.count(); + const hasMoreThan4Messages = await messageModel.hasMoreThanN(4); const sessionModel = new SessionModel(serverDB, ctx.userId); - const sessionCount = await sessionModel.count(); + const hasAnyMessages = await messageModel.hasMoreThanN(0); + const hasExtraSession = await sessionModel.hasMoreThanN(1); return { - canEnablePWAGuide: messageCount >= 4, - canEnableTrace: messageCount >= 4, + canEnablePWAGuide: hasMoreThan4Messages, + canEnableTrace: hasMoreThan4Messages, // 有消息,或者创建过助手,则认为有 conversation - hasConversation: messageCount > 0 || sessionCount > 1, + hasConversation: hasAnyMessages || hasExtraSession, // always return true for community version isOnboard: state.isOnboarded || true, From 7431cd02badb9370b66c089e894cbf54f4d38d19 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 19 Dec 2024 13:25:10 +0000 Subject: [PATCH 2/3] :bookmark: chore(release): v1.36.36 [skip ci] ### [Version 1.36.36](https://github.com/lobehub/lobe-chat/compare/v1.36.35...v1.36.36) Released on **2024-12-19**
Improvements and Fixes
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
--- CHANGELOG.md | 17 +++++++++++++++++ package.json | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 890dedce2fe1..bc72fcf0505d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ # Changelog +### [Version 1.36.36](https://github.com/lobehub/lobe-chat/compare/v1.36.35...v1.36.36) + +Released on **2024-12-19** + +
+ +
+Improvements and Fixes + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ ### [Version 1.36.35](https://github.com/lobehub/lobe-chat/compare/v1.36.34...v1.36.35) Released on **2024-12-18** diff --git a/package.json b/package.json index 6a0ff07b59fc..f1456ffa7b88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lobehub/chat", - "version": "1.36.35", + "version": "1.36.36", "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.", "keywords": [ "framework", From 429c480df07b7d65feaaeb590118f412156eb084 Mon Sep 17 00:00:00 2001 From: lobehubbot Date: Thu, 19 Dec 2024 13:26:08 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20docs(bot):=20Auto=20sync=20a?= =?UTF-8?q?gents=20&=20plugin=20to=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/v1.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog/v1.json b/changelog/v1.json index 37a88fad9547..55ae9614e35f 100644 --- a/changelog/v1.json +++ b/changelog/v1.json @@ -1,4 +1,9 @@ [ + { + "children": {}, + "date": "2024-12-19", + "version": "1.36.36" + }, { "children": { "improvements": ["Improve home page loading for better UX."]