[PR #24024] [MERGED] perf(chats): drop redundant db.refresh after commit in update_chat_by_id #131147

Closed
opened 2026-05-21 16:14:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24024
Author: @runixer
Created: 4/23/2026
Status: Merged
Merged: 4/24/2026
Merged by: @tjbck

Base: devHead: perf/drop-refresh-update-chat-by-id


📝 Commits (1)

  • 4532a17 perf(chats): drop redundant db.refresh after commit in update_chat_by_id

📊 Changes

1 file changed (+0 additions, -1 deletions)

View changed files

📝 backend/open_webui/models/chats.py (+0 -1)

📄 Description

Pull Request Checklist

  • Target branch: dev
  • Description + reasoning below
  • Changelog entry at bottom
  • No docs changes (backend-only, no user-facing behaviour)
  • No new or upgraded dependencies
  • Testing: patch is running in our production fork (pre-0.9 branch) since 2026-04-20; same single-line removal reapplied to the async version on dev. I have not yet run 0.9.1 in production.
  • Agentic AI Code: change drafted with AI assistance, then human-reviewed, human-tested, and deployed to production. It is a single-line deletion; I understand the policy.
  • Code review: self-reviewed
  • Git Hygiene: single atomic commit rebased on dev
  • Title prefix: perf

Changelog Entry

  • Skip redundant refresh on large-chat writes. Chats.update_chat_by_id no longer issues await db.refresh(chat_item) after commit(). The chat table has no server-side defaults, triggers, or computed columns, and every field the method modifies (chat, title, updated_at) is set explicitly from Python values. The refresh was round-tripping the entire chat.chat JSON blob over the wire and through the driver's JSON decoder without producing different data.

Description

Hit during perf work on chats where chat.chat had grown to tens of MB (long RAG-heavy conversations). db.refresh here is pure overhead:

  • No DEFAULT clause, no SERIAL/IDENTITY, no triggers on chat (verified on PostgreSQL: SELECT * FROM pg_trigger WHERE tgrelid = 'chat'::regclass AND NOT tgisinternal is empty).
  • meta has server_default='{}' but that applies to INSERT only; UPDATE does not re-populate it, and update_chat_by_id does not touch meta.
  • Every column set in the method comes from an explicit Python value above; JSON round-trip through the driver is idempotent for valid JSON.

All callers of update_chat_by_id return the resulting ChatModel immediately and do not read fields that could change server-side.

Testing

Patch running in our production fork since 2026-04-20 over a ~35k-row chat table, no functional regressions. The tested path was the pre-async (sync) implementation; the single-line removal is semantically identical in the async variant on dev.

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/24024 **Author:** [@runixer](https://github.com/runixer) **Created:** 4/23/2026 **Status:** ✅ Merged **Merged:** 4/24/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `perf/drop-refresh-update-chat-by-id` --- ### 📝 Commits (1) - [`4532a17`](https://github.com/open-webui/open-webui/commit/4532a17ca743762fa8d0aab75c9fbd49b7921bcb) perf(chats): drop redundant db.refresh after commit in update_chat_by_id ### 📊 Changes **1 file changed** (+0 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/chats.py` (+0 -1) </details> ### 📄 Description # Pull Request Checklist - [x] Target branch: `dev` - [x] Description + reasoning below - [x] Changelog entry at bottom - [x] No docs changes (backend-only, no user-facing behaviour) - [x] No new or upgraded dependencies - [x] Testing: patch is running in our production fork (pre-0.9 branch) since 2026-04-20; same single-line removal reapplied to the async version on `dev`. I have not yet run 0.9.1 in production. - [x] Agentic AI Code: change drafted with AI assistance, then human-reviewed, human-tested, and deployed to production. It is a single-line deletion; I understand the policy. - [x] Code review: self-reviewed - [x] Git Hygiene: single atomic commit rebased on `dev` - [x] Title prefix: **perf** # Changelog Entry - ⚡ **Skip redundant refresh on large-chat writes.** `Chats.update_chat_by_id` no longer issues `await db.refresh(chat_item)` after `commit()`. The `chat` table has no server-side defaults, triggers, or computed columns, and every field the method modifies (`chat`, `title`, `updated_at`) is set explicitly from Python values. The refresh was round-tripping the entire `chat.chat` JSON blob over the wire and through the driver's JSON decoder without producing different data. ### Description Hit during perf work on chats where `chat.chat` had grown to tens of MB (long RAG-heavy conversations). `db.refresh` here is pure overhead: - No `DEFAULT` clause, no `SERIAL`/`IDENTITY`, no triggers on `chat` (verified on PostgreSQL: `SELECT * FROM pg_trigger WHERE tgrelid = 'chat'::regclass AND NOT tgisinternal` is empty). - `meta` has `server_default='{}'` but that applies to INSERT only; UPDATE does not re-populate it, and `update_chat_by_id` does not touch `meta`. - Every column set in the method comes from an explicit Python value above; JSON round-trip through the driver is idempotent for valid JSON. All callers of `update_chat_by_id` return the resulting `ChatModel` immediately and do not read fields that could change server-side. ### Testing Patch running in our production fork since 2026-04-20 over a ~35k-row `chat` table, no functional regressions. The tested path was the pre-async (sync) implementation; the single-line removal is semantically identical in the async variant on `dev`. ### Contributor License Agreement - [x] 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. --- <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-21 16:14:27 -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#131147