diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 439a708d7c..e903afde9c 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -2522,7 +2522,7 @@ class ChatTable: columns = [] for index, tag_id in enumerate(tag_ids): tag_id = tag_id.replace(' ', '_').lower() - stmt = select(func.count(Chat.id)).filter_by(user_id=user_id, archived=False) + stmt = select(func.count(Chat.id)).filter_by(user_id=user_id) stmt = stmt.where(Chat.meta['internal'].as_boolean().is_not(True)) param = f'tag_id_{index}' if dialect_name == 'sqlite': @@ -2550,7 +2550,7 @@ class ChatTable: db: AsyncSession | None = None, ) -> None: """Delete tag rows from *tag_ids* that appear in at most *threshold* - non-archived chats for *user_id*. One query to find orphans, one to + chats for *user_id*. One query to find orphans, one to delete them. Use threshold=0 after a tag is already removed from a chat's meta. diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 95d15bbbc3..9f469fabf9 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -2014,8 +2014,6 @@ async def archive_chat_by_id( if chat.archived: # Cancel any in-flight LLM tasks before archiving await stop_item_tasks(request.app.state.redis, id) - # Archived chats are excluded from count — clean up orphans - await Chats.delete_orphan_tags_for_user(tag_ids, user.id, db=db) else: # Unarchived — ensure tag rows exist await Tags.ensure_tags_exist(tag_ids, user.id, db=db)