mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 13:55:19 +00:00
Merge pull request #17159 from sihyeonn/perf/sh-prompts
perf: fix N+1 query issue in get_prompts method
This commit is contained in:
commit
308f4d6b26
1 changed files with 9 additions and 3 deletions
|
|
@ -103,10 +103,16 @@ class PromptsTable:
|
||||||
|
|
||||||
def get_prompts(self) -> list[PromptUserResponse]:
|
def get_prompts(self) -> list[PromptUserResponse]:
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
prompts = []
|
all_prompts = db.query(Prompt).order_by(Prompt.timestamp.desc()).all()
|
||||||
|
|
||||||
for prompt in db.query(Prompt).order_by(Prompt.timestamp.desc()).all():
|
user_ids = list(set(prompt.user_id for prompt in all_prompts))
|
||||||
user = Users.get_user_by_id(prompt.user_id)
|
|
||||||
|
users = Users.get_users_by_user_ids(user_ids) if user_ids else []
|
||||||
|
users_dict = {user.id: user for user in users}
|
||||||
|
|
||||||
|
prompts = []
|
||||||
|
for prompt in all_prompts:
|
||||||
|
user = users_dict.get(prompt.user_id)
|
||||||
prompts.append(
|
prompts.append(
|
||||||
PromptUserResponse.model_validate(
|
PromptUserResponse.model_validate(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue