Skip to content

Commit

Permalink
match queries to indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Mar 28, 2024
1 parent 5a74cbb commit d3dda29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
// except according to the terms contained in the LICENSE file.

const up = async (db) => {
await db.raw('DROP INDEX audits_details_entity_index');
await db.raw("CREATE INDEX audits_details_entity_def_index ON audits USING HASH (((details ->> 'entityDefId')::INTEGER))");
await db.raw("CREATE INDEX audits_details_entity_source_index ON audits USING HASH (((details ->> 'sourceId')::INTEGER))");
};

const down = async (db) => {
await db.raw("CREATE INDEX audits_details_entity_index ON audits USING HASH (((details ->> 'entityId')::INTEGER))");
await db.raw('DROP INDEX audits_details_entity_def_index');
await db.raw('DROP INDEX audits_details_entity_source_index');
};
Expand Down
4 changes: 2 additions & 2 deletions lib/model/query/audits.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ${extend|| sql`
LEFT OUTER JOIN actors ON actors.id=audits."actorId"
-- if event references entityId in details
LEFT JOIN entities ON (audits.details->'entityId')::INTEGER = entities.id AND entities."deletedAt" IS NULL
LEFT JOIN entities ON (audits.details->>'entityId')::INTEGER = entities.id AND entities."deletedAt" IS NULL
-- join with current entity def even if there is a specific def linked in event
LEFT JOIN entity_defs AS current_entity_def ON current_entity_def."entityId" = entities.id AND current
`}
Expand Down Expand Up @@ -136,7 +136,7 @@ const _getByEntityId = (fields, options, entityId) => sql`
SELECT ${fields} FROM entity_defs
LEFT JOIN entity_def_sources on entity_def_sources.id = entity_defs."sourceId"
INNER JOIN audits ON ((audits.details->'entityDefId')::INTEGER = entity_defs.id OR (audits.details->'sourceId')::INTEGER = entity_def_sources.id)
INNER JOIN audits ON ((audits.details->>'entityDefId')::INTEGER = entity_defs.id OR (audits.details->>'sourceId')::INTEGER = entity_def_sources.id)
LEFT JOIN actors ON actors.id=audits."actorId"
Expand Down

0 comments on commit d3dda29

Please sign in to comment.