Skip to content

Commit

Permalink
Merge pull request #461 from DFE-Digital/feature/NSA-8025_update_audi…
Browse files Browse the repository at this point in the history
…t_query

[NSA-8025] Update Audit ID query to avoid timeouts
  • Loading branch information
JaredAMarsh authored Apr 29, 2024
2 parents 19c91af + 3c7f4d1 commit 3a8a46a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/infrastructure/audit/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3a8a46a

Please sign in to comment.