Summary: Fixes critical OOM crashes (#22206) by implementing server-side pagination and optimizing memory-intensive database queries.
The Problem:
High-volume endpoints like /api/v1/chats/all, /api/v1/memories/, and /api/v1/evaluations/ load entire datasets into memory at once, causing OOM crashes on enterprise-scale instances.
The Fix:
Atomic Commit: Rebased against upstream/dev and squashed into a single commit.
Server-side Pagination: Added skip and limit to SQLAlchemy queries in chats.py, feedbacks.py, memories.py, and messages.py.
Optimized Deletion: Replaced Python-side materialization in delete_shared_chats_by_user_id with a correlated subquery.
Omitted Tests: Test files removed per maintainer request.
Testing & Validation:
✅Personal Testing: I have personally tested ALL changes in this PR.
✅Methodology: Verified pagination by seeding a local PostgreSQL database with 5,000+ chat and memory records.
✅Result: Confirmed that memory usage remains stable (O(1) relative to total record count) during high-offset fetches.
Contributor License Agreement
I certify that this contribution is my own original work and that I have the right to submit it under the project's license.
contributor license agreement
I agree to the terms of the contributor license agreement.
🔄 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/22243
**Author:** [@batrapulkit](https://github.com/batrapulkit)
**Created:** 3/4/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `fix/api-memory-pagination`
---
### 📝 Commits (1)
- [`0d648e1`](https://github.com/open-webui/open-webui/commit/0d648e1c529962184e00f94c882567bb41f89b66) fix: implement server-side pagination for chats/files/memories (#22206)
### 📊 Changes
**4 files changed** (+113 additions, -22 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/models/chats.py` (+60 -12)
📝 `backend/open_webui/models/feedbacks.py` (+22 -3)
📝 `backend/open_webui/models/memories.py` (+26 -4)
📝 `backend/open_webui/models/messages.py` (+5 -3)
</details>
### 📄 Description
**Summary**: Fixes critical OOM crashes (#22206) by implementing server-side pagination and optimizing memory-intensive database queries.
**The Problem**:
High-volume endpoints like `/api/v1/chats/all`, `/api/v1/memories/`, and `/api/v1/evaluations/` load entire datasets into memory at once, causing OOM crashes on enterprise-scale instances.
**The Fix**:
* **Atomic Commit**: Rebased against `upstream/dev` and squashed into a single commit.
* **Server-side Pagination**: Added `skip` and `limit` to SQLAlchemy queries in `chats.py`, `feedbacks.py`, `memories.py`, and `messages.py`.
* **Optimized Deletion**: Replaced Python-side materialization in `delete_shared_chats_by_user_id` with a correlated subquery.
* **Omitted Tests**: Test files removed per maintainer request.
**Testing & Validation**:
* ✅ **Personal Testing**: I have personally tested ALL changes in this PR.
* ✅ **Methodology**: Verified pagination by seeding a local PostgreSQL database with 5,000+ chat and memory records.
* ✅ **Result**: Confirmed that memory usage remains stable (O(1) relative to total record count) during high-offset fetches.
**Contributor License Agreement**
I certify that this contribution is my own original work and that I have the right to submit it under the project's license.
**contributor license agreement**
I agree to the terms of the contributor license agreement.
Fixes #22206
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/22243
Author: @batrapulkit
Created: 3/4/2026
Status: ❌ Closed
Base:
dev← Head:fix/api-memory-pagination📝 Commits (1)
0d648e1fix: implement server-side pagination for chats/files/memories (#22206)📊 Changes
4 files changed (+113 additions, -22 deletions)
View changed files
📝
backend/open_webui/models/chats.py(+60 -12)📝
backend/open_webui/models/feedbacks.py(+22 -3)📝
backend/open_webui/models/memories.py(+26 -4)📝
backend/open_webui/models/messages.py(+5 -3)📄 Description
Summary: Fixes critical OOM crashes (#22206) by implementing server-side pagination and optimizing memory-intensive database queries.
The Problem:
High-volume endpoints like
/api/v1/chats/all,/api/v1/memories/, and/api/v1/evaluations/load entire datasets into memory at once, causing OOM crashes on enterprise-scale instances.The Fix:
upstream/devand squashed into a single commit.skipandlimitto SQLAlchemy queries inchats.py,feedbacks.py,memories.py, andmessages.py.delete_shared_chats_by_user_idwith a correlated subquery.Testing & Validation:
Contributor License Agreement
I certify that this contribution is my own original work and that I have the right to submit it under the project's license.
contributor license agreement
I agree to the terms of the contributor license agreement.
Fixes #22206
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.