Closed kbrock closed 3 days ago
@miq-bot cross-repo-test /all
Backported to radjabov
in commit a582ab53ca80ab23cd21b9b049c895ea7173a745.
commit a582ab53ca80ab23cd21b9b049c895ea7173a745
Author: Jason Frey <fryguy9@gmail.com>
Date: Fri Nov 22 10:40:44 2024 -0500
Merge pull request #23277 from kbrock/preload_associations
Avoid scope query when preloading
(cherry picked from commit 82d5b6230b1f9a59801104ce6d07dbe517ca647d)
MiqPreloader.preload(...,...,scope) correctly identifies the scope coming in and passes off to the preloader
This prevents an extra (big) query from being performed
When we upgraded from rails 6.1 to 7.0, the preloader interface changed. We spent most of our efforts on how that affected virtual attributes, but there was one change here.
We only use preload with a scope in one spot - for preloading
VimPerformanceState
. Joe had documented all the places in the preloader test where the number of records loaded were different. The very name of the variablescope
suggests that this code change is correct and should not point torecords
This change gets those test values back to where they need to be for all but one (?) of the cases. But of interest, we have a lot of tests talking about arrays instead of scopes. Now in use, we only ever pass scopes. But the tests were (probably) introduced when I was trying to treat that scope as a preloaded records implementation. Never got it working correctly and ended up reverting to
preload_with_array
instead.I'm thinking we should remove these preload with an array tests since this method was only ever written for passing a scope that was later applied to the records
EDIT:
Performance Testing
With a small database with 328 Vms and 380,000 vim performance states, passing a vim performance states scope to
MiqPreloader.preload
:Before
After