[PR #21012] [CLOSED] perf: eliminate N+1 query for is_user_active in channels #25886

Closed
opened 2026-04-20 06:11:01 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21012
Author: @Classic298
Created: 1/28/2026
Status: Closed

Base: devHead: channels-perf


📝 Commits (1)

  • d7b0441 perf: eliminate N+1 query for is_user_active in channels

📊 Changes

1 file changed (+12 additions, -7 deletions)

View changed files

📝 backend/open_webui/routers/channels.py (+12 -7)

📄 Description

Summary

Eliminates N+1 database queries when computing is_active status for DM channel users. Previously, Users.is_user_active was called per user, causing a separate database query for each.

Changes

routers/channels.py get_channels endpoint:

  • Compute is_active directly from user.last_active_at instead of calling is_user_active
  • Added time import for the 3-minute threshold calculation
  • Uses same logic as is_user_active (active if last_active_at within 3 minutes)

Performance Impact

Before: N queries for N users in DM channels
After: 0 additional queries - uses already-fetched user data

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/21012 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/28/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `channels-perf` --- ### 📝 Commits (1) - [`d7b0441`](https://github.com/open-webui/open-webui/commit/d7b0441fa7b154654002e3149c25f25c893157e8) perf: eliminate N+1 query for is_user_active in channels ### 📊 Changes **1 file changed** (+12 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/channels.py` (+12 -7) </details> ### 📄 Description ## Summary Eliminates N+1 database queries when computing is_active status for DM channel users. Previously, Users.is_user_active was called per user, causing a separate database query for each. ## Changes routers/channels.py get_channels endpoint: - Compute is_active directly from user.last_active_at instead of calling is_user_active - Added time import for the 3-minute threshold calculation - Uses same logic as is_user_active (active if last_active_at within 3 minutes) ## Performance Impact Before: N queries for N users in DM channels After: 0 additional queries - uses already-fetched user data ### Contributor License Agreement 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-04-20 06:11:01 -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#25886