You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Preload nested RBAC associations to reduce N+1 queries
API requests with nested RBAC associations (hardware.host.name,
ext_management_system.name, storage.name, ems_cluster.name) were
causing N+1 queries.
Removed RBAC check in 'determine_include_for_find' to allow eager loading
of nested RBAC associations. Previously these were skipped, causing a
query for each VM or similar collection.
Now they're eager-loaded and RBAC re-filters in bulk.
For example, in a specific database setup with ~1000 vms returned, and the
following API request:
http://localhost:3000/api/vms?expand=resources&attributes=name,hardware.host.name,ext_management_system.name,storage.name
The query count looks like this:
Before:
Completed 200 OK in 4530ms (Views: 0.3ms | ActiveRecord: 1401.9ms (2207 queries, 1152 cached) | GC: 479.2ms)
After:
Completed 200 OK in 3168ms (Views: 0.3ms | ActiveRecord: 541.5ms (787 queries, 763 cached) | GC: 461.6ms)
Reduction of queries from 2207 to 787 (64%).
Fixes#1321
0 commit comments