From 3c7f4d18326b05e02e5792c55d5b1c851bcdcefd Mon Sep 17 00:00:00 2001 From: Jared Marsh Date: Thu, 25 Apr 2024 17:02:50 +0100 Subject: [PATCH] [NSA-8025] Update Audit ID query to avoid timeouts This query has been tested in the DB/locally to run faster and more consistently. --- src/infrastructure/audit/sequelize.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/infrastructure/audit/sequelize.js b/src/infrastructure/audit/sequelize.js index adeb5080..57e8ff92 100644 --- a/src/infrastructure/audit/sequelize.js +++ b/src/infrastructure/audit/sequelize.js @@ -52,8 +52,16 @@ const getPageOfUserAudits = async (userId, pageNumber) => { const queryWhere = ` WHERE type != 'technical-audit' AND id IN ( - SELECT AL.id FROM AuditLogs AL LEFT JOIN AuditLogMeta ALM on AL.id = ALM.auditId - WHERE AL.userId = :userId OR (ALM.[key] IN ('editedUser', 'viewedUser') AND ALM.[value] = :userId) + SELECT AL.id + FROM AuditLogs AL + WHERE AL.userId = :userId + UNION + SELECT AL.id + FROM AuditLogs AL + JOIN AuditLogMeta ALM + ON ALM.auditId = AL.id + WHERE ALM.[key] IN ('editedUser', 'viewedUser') + AND ALM.[Value] = :userId )`; const queryOpts = { type: QueryTypes.SELECT,