From d5dbf286cc3e5ec70639bf378a6d46e7aa587379 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 19:02:20 -0500 Subject: [PATCH] Add missing database indexes for `hooks.unfurl` endpoint (#10870) * Initial plan * Add database indexes to improve hooks.unfurl performance Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Verify migrations and query plans for new indexes Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Address code review feedback: improve migration rollback order and add comments Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Change index column order to teamId first as requested Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Update .env.test --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> Co-authored-by: Tom Moor --- .env.test | 1 + ...dd-authentications-service-teamid-index.js | 16 +++++++++++ ...egrations-service-type-settings-indexes.js | 27 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 server/migrations/20251212232400-add-authentications-service-teamid-index.js create mode 100644 server/migrations/20251212232500-add-integrations-service-type-settings-indexes.js diff --git a/.env.test b/.env.test index ceee6d86a5..fa09bedff2 100644 --- a/.env.test +++ b/.env.test @@ -12,6 +12,7 @@ GOOGLE_CLIENT_SECRET=123 SLACK_CLIENT_ID=123 SLACK_CLIENT_SECRET=123 +SLACK_VERIFICATION_TOKEN=test-token-123 GITHUB_CLIENT_ID=123; GITHUB_CLIENT_SECRET=123; diff --git a/server/migrations/20251212232400-add-authentications-service-teamid-index.js b/server/migrations/20251212232400-add-authentications-service-teamid-index.js new file mode 100644 index 0000000000..1400c187c1 --- /dev/null +++ b/server/migrations/20251212232400-add-authentications-service-teamid-index.js @@ -0,0 +1,16 @@ +"use strict"; + +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.addIndex("authentications", ["teamId", "service"], { + name: "authentications_team_id_service", + }); + }, + + async down(queryInterface, Sequelize) { + await queryInterface.removeIndex( + "authentications", + "authentications_team_id_service" + ); + }, +}; diff --git a/server/migrations/20251212232500-add-integrations-service-type-settings-indexes.js b/server/migrations/20251212232500-add-integrations-service-type-settings-indexes.js new file mode 100644 index 0000000000..897f7ff6b5 --- /dev/null +++ b/server/migrations/20251212232500-add-integrations-service-type-settings-indexes.js @@ -0,0 +1,27 @@ +"use strict"; + +module.exports = { + async up(queryInterface, Sequelize) { + // Add composite index on service and type for better filtering + await queryInterface.addIndex("integrations", ["service", "type"], { + name: "integrations_service_type", + }); + + // Add GIN index on settings for JSONB queries + // Using raw SQL as Sequelize doesn't support GIN index type natively + await queryInterface.sequelize.query( + 'CREATE INDEX "integrations_settings_gin" ON "integrations" USING GIN ("settings");' + ); + }, + + async down(queryInterface, Sequelize) { + // Drop indexes in reverse order of creation + await queryInterface.sequelize.query( + 'DROP INDEX IF EXISTS "integrations_settings_gin";' + ); + await queryInterface.removeIndex( + "integrations", + "integrations_service_type" + ); + }, +};