Preload associations when exporting CI pipeline's builds
When exporting the CI pipelines, not all associations are preloaded, which causes N+1 queries causing the CI pipelines to take a long time to export.
The main problem is the statuses
association, which is a polymorphic association, and each "real" association implements different sub-associations which don't allow us to preload them.
For instance, CommitStatus
is the base class. The child classes are Ci::Build
, Ci::Bridge
, and GenericCommitStatus
, and the last doesn't have the association metadata
. Therefore when we export CommitStatus (statuses)
, which incorporates all child classes, the metadata
can't be preloaded as the association doesn't exist for GenericCommitStatus
Solution
- Export each child class as a separate association instead of a unique association called
statuses
- Preload the correct association for each child class
- Implement a solution that is compatible with previous exported files
Edited by Rodrigo Tomonari