Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

perf(rooms): index rooms.group_id (#404)

Abel Dantas8b81eaa2c23f
diff --git a/core/switch_core/db/models.py b/core/switch_core/db/models.py
index dda48abda..91db96e0a 100644
--- a/core/switch_core/db/models.py
+++ b/core/switch_core/db/models.py
@@ -317,6 +317,10 @@ class Room(Base):
unique=True,
postgresql_where=text("external_channel_id IS NOT NULL"),
),
+ # group_id is a foreign key with no index, so listing rooms by group
+ # and the ON DELETE SET NULL when a group is removed both scan the
+ # table. Mirrors ix_agents_parent_agent_id.
+ Index("ix_rooms_group_id", "group_id"),
)
id: Mapped[str] = mapped_column(Text, primary_key=True, default=_uuid)
diff --git a/core/switch_core/migrations/versions/a1c7e2f9b430_index_rooms_group_id.py b/core/switch_core/migrations/versions/a1c7e2f9b430_index_rooms_group_id.py
new file mode 100644
index 000000000..abc13a943
--- /dev/null
+++ b/core/switch_core/migrations/versions/a1c7e2f9b430_index_rooms_group_id.py
@@ -0,0 +1,29 @@
+"""index rooms.group_id
+
+group_id is a foreign key with no index, so listing rooms by group and the
+ON DELETE SET NULL when a group is removed both scan the rooms table. Mirrors
+ix_agents_parent_agent_id.
+
+Revision ID: a1c7e2f9b430
+Revises: c8e4a10b7f36
+Create Date: 2026-09-09 00:00:00.000000
+
+"""
+
+from collections.abc import Sequence
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision: str = "a1c7e2f9b430"
+down_revision: str | None = "c8e4a10b7f36"
+branch_labels: str | Sequence[str] | None = None
+depends_on: str | Sequence[str] | None = None
+
+
+def upgrade() -> None:
+ op.create_index("ix_rooms_group_id", "rooms", ["group_id"])
+
+
+def downgrade() -> None:
+ op.drop_index("ix_rooms_group_id", table_name="rooms")