From 20949179a98b28d79a1d92c0d152e6785a0a8c6a Mon Sep 17 00:00:00 2001 From: DrMelone <27028174+Classic298@users.noreply.github.com> Date: Mon, 2 Mar 2026 23:05:01 +0100 Subject: [PATCH] fix: align analytics message count with token count by filtering on assistant role The get_message_count_by_user query was counting messages of ALL roles (user, assistant, system), while get_token_usage_by_user only aggregated tokens from assistant messages with non-null usage data. This mismatch caused the Admin Panel Analytics to show inflated message counts alongside zero tokens for users whose messages were predominantly user-role messages without any token usage data. Align the message count query with the token usage query by adding a role='assistant' filter, so both metrics reflect the same underlying dataset of assistant responses. --- backend/open_webui/models/chat_messages.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/models/chat_messages.py b/backend/open_webui/models/chat_messages.py index 087662ff7c..2d40cdf83c 100644 --- a/backend/open_webui/models/chat_messages.py +++ b/backend/open_webui/models/chat_messages.py @@ -478,7 +478,10 @@ class ChatMessageTable: stmt = ( select(ChatMessage.user_id, func.count(ChatMessage.id).label('count')) - .filter(~ChatMessage.user_id.like('shared-%')) + .filter( + ChatMessage.role == 'assistant', + ~ChatMessage.user_id.like('shared-%'), + ) ) if start_date: