From a44a612387cd3d76268accc1d73cd50dfb65448d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 8 Sep 2025 02:15:49 +0200 Subject: [PATCH] perf: Add missing indexes (#10124) --- .../20250907220205-add-missing-indexes.js | 18 ++++++++++++++++++ server/queues/processors/BacklinksProcessor.ts | 11 +++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 server/migrations/20250907220205-add-missing-indexes.js diff --git a/server/migrations/20250907220205-add-missing-indexes.js b/server/migrations/20250907220205-add-missing-indexes.js new file mode 100644 index 0000000000..f68bf1cd8e --- /dev/null +++ b/server/migrations/20250907220205-add-missing-indexes.js @@ -0,0 +1,18 @@ +"use strict"; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface) { + await queryInterface.addIndex("revisions", ["createdAt"], { + concurrently: true, + }); + await queryInterface.addIndex("user_permissions", ["sourceId"], { + concurrently: true, + }); + }, + + async down(queryInterface) { + await queryInterface.removeIndex("user_permissions", ["sourceId"]); + await queryInterface.removeIndex("revisions", ["createdAt"]); + }, +}; diff --git a/server/queues/processors/BacklinksProcessor.ts b/server/queues/processors/BacklinksProcessor.ts index 13008854a4..d12d8c9c60 100644 --- a/server/queues/processors/BacklinksProcessor.ts +++ b/server/queues/processors/BacklinksProcessor.ts @@ -19,10 +19,15 @@ export default class BacklinksProcessor extends BaseProcessor { if (!document) { return; } + + // Note: These can be UUID or slugs const linkIds = DocumentHelper.parseDocumentIds(document); + await Promise.all( linkIds.map(async (linkId) => { - const linkedDocument = await Document.findByPk(linkId); + const linkedDocument = await Document.findByPk(linkId, { + attributes: ["id"], + }); if (!linkedDocument || linkedDocument.id === event.documentId) { return; @@ -61,7 +66,9 @@ export default class BacklinksProcessor extends BaseProcessor { // create or find existing backlink records for referenced docs await Promise.all( linkIds.map(async (linkId) => { - const linkedDocument = await Document.findByPk(linkId); + const linkedDocument = await Document.findByPk(linkId, { + attributes: ["id"], + }); if (!linkedDocument || linkedDocument.id === event.documentId) { return;