mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 05:24:02 +00:00
refac
This commit is contained in:
parent
efd4b03f78
commit
de6b5a7bbe
@ -249,22 +249,25 @@ class ChatTable:
|
|||||||
self,
|
self,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
include_archived: bool = False,
|
include_archived: bool = False,
|
||||||
skip: int = 0,
|
skip: Optional[int] = None,
|
||||||
limit: int = -1,
|
limit: Optional[int] = None,
|
||||||
) -> list[ChatTitleIdResponse]:
|
) -> list[ChatTitleIdResponse]:
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
query = db.query(Chat).filter_by(user_id=user_id)
|
query = db.query(Chat).filter_by(user_id=user_id)
|
||||||
if not include_archived:
|
if not include_archived:
|
||||||
query = query.filter_by(archived=False)
|
query = query.filter_by(archived=False)
|
||||||
|
|
||||||
all_chats = (
|
query = query.order_by(Chat.updated_at.desc()).with_entities(
|
||||||
query.order_by(Chat.updated_at.desc())
|
Chat.id, Chat.title, Chat.updated_at, Chat.created_at
|
||||||
# limit cols
|
|
||||||
.with_entities(Chat.id, Chat.title, Chat.updated_at, Chat.created_at)
|
|
||||||
.limit(limit)
|
|
||||||
.offset(skip)
|
|
||||||
.all()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
query = query.limit(limit)
|
||||||
|
if skip:
|
||||||
|
query = query.offset(skip)
|
||||||
|
|
||||||
|
all_chats = query.all()
|
||||||
|
|
||||||
# result has to be destrctured from sqlalchemy `row` and mapped to a dict since the `ChatModel`is not the returned dataclass.
|
# result has to be destrctured from sqlalchemy `row` and mapped to a dict since the `ChatModel`is not the returned dataclass.
|
||||||
return [
|
return [
|
||||||
ChatTitleIdResponse.model_validate(
|
ChatTitleIdResponse.model_validate(
|
||||||
|
Loading…
Reference in New Issue
Block a user