mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
perf(chatd): remove redundant chat rereads (#23161)
## Summary This PR removes two redundant chat rereads in `chatd`. ### Archive / unarchive - `archiveChat` and `unarchiveChat` already come through `httpmw.ChatParam`, so the handlers already have the `database.Chat` row. - Pass that row into `chatd.ArchiveChat` / `chatd.UnarchiveChat` instead of rereading by ID before publishing the sidebar events. ### End-of-turn cleanup - `processChat` no longer calls `GetChatByID` after the cleanup transaction just to refresh the chat snapshot. - Title generation already persists the generated title and emits its own `title_change` event. - To preserve best-effort title freshness for the cleanup path, the async title-generation goroutine stores the generated title in per-turn shared state and cleanup overlays it if available before publishing the `status_change` event and dispatching push notifications. ## Why - removes one DB read from archive / unarchive requests - removes one DB read from completed turns, which is the larger hot-path win - keeps the existing pubsub/event contract intact instead of broadening this into a larger event-model redesign ## Notes - `title_change` remains the authoritative title update for clients - cleanup does not wait for title generation; it uses the generated title only when it is already available
This commit is contained in:
+2
-2
@@ -1386,7 +1386,7 @@ func (api *API) archiveChat(rw http.ResponseWriter, r *http.Request) {
|
||||
// active subscribers. Fall back to direct DB for the
|
||||
// simple archive flag — no streaming state is involved.
|
||||
if api.chatDaemon != nil {
|
||||
err = api.chatDaemon.ArchiveChat(ctx, chat.ID)
|
||||
err = api.chatDaemon.ArchiveChat(ctx, chat)
|
||||
} else {
|
||||
err = api.Database.ArchiveChatByID(ctx, chat.ID)
|
||||
}
|
||||
@@ -1417,7 +1417,7 @@ func (api *API) unarchiveChat(rw http.ResponseWriter, r *http.Request) {
|
||||
// active subscribers. Fall back to direct DB for the
|
||||
// simple unarchive flag — no streaming state is involved.
|
||||
if api.chatDaemon != nil {
|
||||
err = api.chatDaemon.UnarchiveChat(ctx, chat.ID)
|
||||
err = api.chatDaemon.UnarchiveChat(ctx, chat)
|
||||
} else {
|
||||
err = api.Database.UnarchiveChatByID(ctx, chat.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user