Commit b5c45f2
Add missing Actor index to Audit Logs table (#2256)
Add concurrent index on `(actor_type, actor_id)` columns to `audit_logs`
table
to dramatically improve performance of audit log queries for devices and
users.
The missing index was causing full table scans on **5M+** record tables,
resulting in 25+ second query times. With the index, query time drops to
~10ms.
### The Problem
The issue on a line 75
https://github.com/nerves-hub/nerves_hub_web/blob/1191d27ad2b5003fee99c9994c1a052d61304653/lib/nerves_hub/audit_logs.ex#L70-L84
### Existing indexes on audit_logs:
- `audit_logs_org_id_inserted_at_index`: [inserted_at, org_id]
- `audit_logs_pkey` (PRIMARY KEY): [id]
- `audit_logs_resource_type_resource_id_index`: [resource_id,
resource_type]
### Implementation Details
- Uses CREATE INDEX CONCURRENTLY to avoid table locks during deployment
- Uses create_if_not_exists for idempotency
- Includes proper migration options `(@disable_ddl_transaction,
@disable_migration_lock)`
### Performance impact:
- Before: 25+ seconds (Seq Scan on `audit_logs`)
- After: ~10ms (Index Scan on `audit_logs_actor_type_actor_id_index`)
Fixes device page slow loading caused by **AuditLogFeed** component.
Co-authored-by: Taras Tyshko <[email protected]>1 parent 1191d27 commit b5c45f2
File tree
1 file changed
+10
-0
lines changed- priv/repo/migrations
1 file changed
+10
-0
lines changedLines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments