Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

perf(db): index assistant chat messages by task (MUL-7230) (#8244)

Multica Eve0c886a1c9e02
diff --git a/server/cmd/migrate/main.go b/server/cmd/migrate/main.go
index b3fe576d08..0b51f6590d 100644
--- a/server/cmd/migrate/main.go
+++ b/server/cmd/migrate/main.go
@@ -300,6 +300,7 @@ var concurrentIndexCleanups = map[string]string{
"446_issue_properties_bigm_index": "idx_issue_properties_bigm",
"452_agent_task_pending_thread_unique": "idx_one_pending_task_per_issue_agent_thread",
"458_activity_log_member_assignee_frequency_index": "idx_activity_log_member_assignee_frequency",
+ "459_chat_message_assistant_task_index": "idx_chat_message_assistant_task",
}
// concurrentDownIndexCleanups covers every migration whose down direction
diff --git a/server/migrations/459_chat_message_assistant_task_index.down.sql b/server/migrations/459_chat_message_assistant_task_index.down.sql
new file mode 100644
index 0000000000..1e0f26471a
--- /dev/null
+++ b/server/migrations/459_chat_message_assistant_task_index.down.sql
@@ -0,0 +1 @@
+DROP INDEX CONCURRENTLY IF EXISTS idx_chat_message_assistant_task;
diff --git a/server/migrations/459_chat_message_assistant_task_index.up.sql b/server/migrations/459_chat_message_assistant_task_index.up.sql
new file mode 100644
index 0000000000..8123b3b5fc
--- /dev/null
+++ b/server/migrations/459_chat_message_assistant_task_index.up.sql
@@ -0,0 +1,11 @@
+-- Index the task-owned assistant lookup used by quick-action generation.
+--
+-- GetChatMessageByTaskAssistant and SetChatMessageQuickActionsByTask both find
+-- the newest assistant row for one task. The existing task_id index is partial
+-- on role = 'user', so neither query can use it and both scan chat_message.
+--
+-- Single-statement migration: CREATE INDEX CONCURRENTLY cannot run inside a
+-- transaction or a multi-command string.
+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_chat_message_assistant_task
+ ON chat_message (task_id, created_at DESC)
+ WHERE role = 'assistant';