Alerting: Replace index role_id, action, scope with action, scope, role_id on permission table (#80336)

* Alerting: Add action, scope, role_id to permission table

The existing role_id, action, scope index has the wrong ordering to be most
effectively used in dashboard/folder permission requests.

On a large tests set, the slow database calls were on the order of ~30-40ms, so
when performed individually they don't have that large of a latency impact.
However, when done in bulk in the migration this adds up to some very slow
requests.

After the index is added these same database calls are reduced to ~4-5ms

* Change index to action, scope, role_id

* Make new index unique and drop [role_id, action, scope] index
This commit is contained in:
Matthew Jacobson 2024-01-24 16:18:14 -05:00 committed by GitHub
parent 71e70c424f
commit e45f664ca4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -186,4 +186,14 @@ func AddMigration(mg *migrator.Migrator) {
mg.AddMigration("add permission identifier index", migrator.NewAddIndexMigration(permissionV1, &migrator.Index{
Cols: []string{"identifier"},
}))
mg.AddMigration("add permission action scope role_id index", migrator.NewAddIndexMigration(permissionV1, &migrator.Index{
Type: migrator.UniqueIndex,
Cols: []string{"action", "scope", "role_id"},
}))
mg.AddMigration("remove permission role_id action scope index", migrator.NewDropIndexMigration(permissionV1, &migrator.Index{
Type: migrator.UniqueIndex,
Cols: []string{"role_id", "action", "scope"},
}))
}