[PR #22165] [CLOSED] fix: align analytics message count with token count by filtering on assistant role #81398

Closed
opened 2026-05-13 15:45:12 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22165
Author: @Classic298
Created: 3/2/2026
Status: Closed

Base: devHead: fix/analytics-message-count-role-filter


📝 Commits (2)

  • 2094917 fix: align analytics message count with token count by filtering on assistant role
  • 51d7cc8 Merge branch 'dev' into fix/analytics-message-count-role-filter

📊 Changes

1 file changed (+6 additions, -2 deletions)

View changed files

📝 backend/open_webui/models/chat_messages.py (+6 -2)

📄 Description

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.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22165 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 3/2/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/analytics-message-count-role-filter` --- ### 📝 Commits (2) - [`2094917`](https://github.com/open-webui/open-webui/commit/20949179a98b28d79a1d92c0d152e6785a0a8c6a) fix: align analytics message count with token count by filtering on assistant role - [`51d7cc8`](https://github.com/open-webui/open-webui/commit/51d7cc8f184f195826e8dc757be6563f10fce1e8) Merge branch 'dev' into fix/analytics-message-count-role-filter ### 📊 Changes **1 file changed** (+6 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/chat_messages.py` (+6 -2) </details> ### 📄 Description 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. ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-13 15:45:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#81398