Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
3b487cfa
Unverified
Commit
3b487cfa
authored
Jul 24, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Jul 24, 2024
Browse files
Merge pull request #4046 from thearyadev/chat-list-optimization
perf: optimize query for chat list
parents
a8d2072e
f531a51e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
backend/apps/webui/models/chats.py
backend/apps/webui/models/chats.py
+34
-0
backend/apps/webui/routers/chats.py
backend/apps/webui/routers/chats.py
+1
-1
No files found.
backend/apps/webui/models/chats.py
View file @
3b487cfa
...
...
@@ -245,6 +245,40 @@ class ChatTable:
)
return
[
ChatModel
.
model_validate
(
chat
)
for
chat
in
all_chats
]
def
get_chat_title_id_list_by_user_id
(
self
,
user_id
:
str
,
include_archived
:
bool
=
False
,
skip
:
int
=
0
,
limit
:
int
=
50
,
)
->
List
[
ChatTitleIdResponse
]:
with
get_db
()
as
db
:
query
=
db
.
query
(
Chat
).
filter_by
(
user_id
=
user_id
)
if
not
include_archived
:
query
=
query
.
filter_by
(
archived
=
False
)
all_chats
=
(
query
.
order_by
(
Chat
.
updated_at
.
desc
())
# limit cols
.
with_entities
(
Chat
.
id
,
Chat
.
title
,
Chat
.
updated_at
,
Chat
.
created_at
).
all
()
)
# result has to be destrctured from sqlalchemy `row` and mapped to a dict since the `ChatModel`is not the returned dataclass.
return
list
(
map
(
lambda
row
:
ChatTitleIdResponse
.
model_validate
(
{
"id"
:
row
[
0
],
"title"
:
row
[
1
],
"updated_at"
:
row
[
2
],
"created_at"
:
row
[
3
],
}
),
all_chats
,
)
)
def
get_chat_list_by_chat_ids
(
self
,
chat_ids
:
List
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
...
...
backend/apps/webui/routers/chats.py
View file @
3b487cfa
...
...
@@ -45,7 +45,7 @@ router = APIRouter()
async
def
get_session_user_chat_list
(
user
=
Depends
(
get_verified_user
),
skip
:
int
=
0
,
limit
:
int
=
50
):
return
Chats
.
get_chat_list_by_user_id
(
user
.
id
,
skip
,
limit
)
return
Chats
.
get_chat_
title_id_
list_by_user_id
(
user
.
id
,
skip
=
skip
,
limit
=
limit
)
############################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment