From 8989287e8a0045e54e0da9df197fb0f78f9028d1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 26 May 2026 19:56:46 -0400 Subject: [PATCH] perf: Add missing indexes on foreign keys referencing documents (#12473) * perf: Add missing indexes on foreign keys referencing documents Cascade deletes on the documents table were forced into sequential scans on file_operations, share_subscriptions, and access_requests because their documentId columns lacked a usable single-column index. Also fixes lint-staged to skip oxlint when every staged file matches an .oxlintrc.json ignore pattern, since oxlint exits 1 in that case. Co-Authored-By: Claude Opus 4.7 * Handle oxlint no-files exit instead of mirroring ignorePatterns Co-Authored-By: Claude Opus 4.7 --------- Co-authored-by: Claude Opus 4.7 --- lint-staged.config.mjs | 11 ++++++---- ...092836-add-document-foreign-key-indexes.js | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 server/migrations/20260526092836-add-document-foreign-key-indexes.js diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index 84312892e6..a414ff6ef4 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -1,12 +1,15 @@ +// oxlint exits 1 when every input matches .oxlintrc.json ignorePatterns +// (e.g. migration-only commits). Swallow that specific case so the hook +// passes, while still surfacing real lint failures. +const oxlint = (files) => + `bash -c 'out=$(oxlint ${files.join(" ")} --fix --type-aware 2>&1); rc=$?; printf "%s\\n" "$out"; if [ $rc -ne 0 ] && ! printf "%s" "$out" | grep -q "No files found to lint"; then exit $rc; fi'`; + export default { // Run prettier first for formatting, then oxlint for linting, and translation updates on changes to JS and // TypeScript files "**/*.[tj]s?(x)": [ (f) => `prettier --write ${f.join(" ")}`, - (f) => - f.length > 20 - ? `yarn lint --fix` - : `oxlint ${f.join(" ")} --fix --type-aware`, + (f) => (f.length > 20 ? `yarn lint --fix` : oxlint(f)), () => `yarn build:i18n`, () => "git add shared/i18n/locales/en_US/translation.json", ], diff --git a/server/migrations/20260526092836-add-document-foreign-key-indexes.js b/server/migrations/20260526092836-add-document-foreign-key-indexes.js new file mode 100644 index 0000000000..c8749c41a9 --- /dev/null +++ b/server/migrations/20260526092836-add-document-foreign-key-indexes.js @@ -0,0 +1,22 @@ +"use strict"; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface) { + await queryInterface.addIndex("file_operations", ["documentId"], { + concurrently: true, + }); + await queryInterface.addIndex("share_subscriptions", ["documentId"], { + concurrently: true, + }); + await queryInterface.addIndex("access_requests", ["documentId"], { + concurrently: true, + }); + }, + + async down(queryInterface) { + await queryInterface.removeIndex("access_requests", ["documentId"]); + await queryInterface.removeIndex("share_subscriptions", ["documentId"]); + await queryInterface.removeIndex("file_operations", ["documentId"]); + }, +};