[PR #20457] [CLOSED] fix(notes): eliminate N+1 query in get_notes endpoint #41260

Closed
opened 2026-04-25 13:32:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: devHead: notes-perf


📝 Commits (1)

  • 406a9ee fix(notes): eliminate N+1 query in get_notes endpoint

📊 Changes

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

View changed files

📝 backend/open_webui/routers/notes.py (+12 -3)

📄 Description

Replaced per-note user lookup with batch fetch using SQL IN clause.

Changes:

  • Fetch all note user_ids in a single pass
  • Use Users.get_users_by_user_ids() for batch lookup
  • Build user mapping to avoid DB calls in loop

Performance: Reduces N+1 queries to 2 queries (notes + users)

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/20457 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/7/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `notes-perf` --- ### 📝 Commits (1) - [`406a9ee`](https://github.com/open-webui/open-webui/commit/406a9ee45ab35bf9dedcb423330ad19baf477575) fix(notes): eliminate N+1 query in get_notes endpoint ### 📊 Changes **1 file changed** (+12 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/notes.py` (+12 -3) </details> ### 📄 Description Replaced per-note user lookup with batch fetch using SQL IN clause. Changes: - Fetch all note user_ids in a single pass - Use Users.get_users_by_user_ids() for batch lookup - Build user mapping to avoid DB calls in loop Performance: Reduces N+1 queries to 2 queries (notes + users) ### 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-25 13:32:25 -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#41260