From 4b81b12ed4eea005e545767f236ef01ed0c9084d Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 16 Oct 2026 15:20:15 +0400 Subject: [PATCH] chore: format --- backend/open_webui/models/chats.py | 4 +-- backend/open_webui/models/messages.py | 34 ++++++++++++++++++++------ backend/open_webui/routers/channels.py | 4 ++- scripts/encryption/build.py | 4 ++- src/lib/utils/comments/package.ts | 3 ++- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 6478b6849b..67e43bb639 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -1318,9 +1318,7 @@ class ChatTable: chat.current_message_id = history['currentId'] chat.updated_at = int(time.time()) for mid, message in turn.items(): - await ChatMessages.upsert_message( - mid, chat_id, message.get('user_id') or chat.user_id, message, db=db - ) + await ChatMessages.upsert_message(mid, chat_id, message.get('user_id') or chat.user_id, message, db=db) if parent_id: turn[parent_id] = history['messages'][parent_id] return {'messages': turn, 'currentId': history['currentId']} diff --git a/backend/open_webui/models/messages.py b/backend/open_webui/models/messages.py index f49ae09f05..b6e04bb973 100644 --- a/backend/open_webui/models/messages.py +++ b/backend/open_webui/models/messages.py @@ -422,20 +422,38 @@ class MessageTable: stmt = select(Message).filter_by(channel_id=channel_id, parent_id=parent_id) if around or before: anchor = await db.get(Message, before or around) - if not anchor or anchor.channel_id != channel_id or (anchor.id != parent_id and anchor.parent_id != parent_id): + if ( + not anchor + or anchor.channel_id != channel_id + or (anchor.id != parent_id and anchor.parent_id != parent_id) + ): return [] if before: - stmt = stmt.where(or_(Message.created_at < anchor.created_at, - and_(Message.created_at == anchor.created_at, Message.id < anchor.id))) + stmt = stmt.where( + or_( + Message.created_at < anchor.created_at, + and_(Message.created_at == anchor.created_at, Message.id < anchor.id), + ) + ) skip = 0 else: # A bounded window starts just above the match, even in very old threads. - newer = select(func.count()).select_from(Message).where( - Message.channel_id == channel_id, Message.parent_id == parent_id, - or_(Message.created_at > anchor.created_at, - and_(Message.created_at == anchor.created_at, Message.id > anchor.id))) + newer = ( + select(func.count()) + .select_from(Message) + .where( + Message.channel_id == channel_id, + Message.parent_id == parent_id, + or_( + Message.created_at > anchor.created_at, + and_(Message.created_at == anchor.created_at, Message.id > anchor.id), + ), + ) + ) skip = max(0, (await db.scalar(newer)) - 10) - result = await db.execute(stmt.order_by(Message.created_at.desc(), Message.id.desc()).offset(skip).limit(limit)) + result = await db.execute( + stmt.order_by(Message.created_at.desc(), Message.id.desc()).offset(skip).limit(limit) + ) all_messages = list(result.scalars().all()) # If length of all_messages is less than limit, then add the parent message diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 95a0e719b5..805e7fa65b 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -1702,7 +1702,9 @@ async def get_channel_thread_messages( if user.role != 'admin' and not await channel_has_access(user.id, channel, permission='read', db=db): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) - message_list = await Messages.get_messages_by_parent_id(id, message_id, skip, min(max(limit, 1), 100), db=db, around=around, before=before) + message_list = await Messages.get_messages_by_parent_id( + id, message_id, skip, min(max(limit, 1), 100), db=db, around=around, before=before + ) if not message_list: return [] diff --git a/scripts/encryption/build.py b/scripts/encryption/build.py index 9e081e4552..f6368c3db1 100644 --- a/scripts/encryption/build.py +++ b/scripts/encryption/build.py @@ -122,7 +122,9 @@ for package in sorted(metadata['packages'], key=lambda p: (p['name'], p['version f'Source: https://crates.io/api/v1/crates/{package["name"]}/{package["version"]}/download\n' + '\n'.join(references) ) -notices.extend(f'\nLicense and notice text [{number}]\n--------------------------------\n{text}' for text, number in texts.items()) +notices.extend( + f'\nLicense and notice text [{number}]\n--------------------------------\n{text}' for text, number in texts.items() +) (OUTPUT / 'THIRD_PARTY_LICENSES.txt').write_text('\n'.join(notices) + '\n') with tempfile.NamedTemporaryFile(mode='w', suffix='.json') as temp: json.dump(metadata, temp) diff --git a/src/lib/utils/comments/package.ts b/src/lib/utils/comments/package.ts index 6e60b386ba..4073820973 100644 --- a/src/lib/utils/comments/package.ts +++ b/src/lib/utils/comments/package.ts @@ -2,7 +2,8 @@ import JSZip from 'jszip'; export const elements = (node: Document | Element, name: string): Element[] => Array.from(node.getElementsByTagNameNS('*', name)); -export const children = (node: Node): Element[] => Array.from(node.childNodes).filter((n) => n.nodeType === 1) as Element[]; +export const children = (node: Node): Element[] => + Array.from(node.childNodes).filter((n) => n.nodeType === 1) as Element[]; export const attr = (node: Element, name: string) => Array.from(node.attributes).find((a) => a.localName === name)?.value ?? ''; export const text = (node: Element, paragraph = 'p') => {