Fix N+1 when validating groups
What does this MR do?
validates_associated
calls #valid?
on each object in the assocation. This means for groups with a large number of runners, thousands of queries can be run when validating.
This removes this line as we do not really need this.
History of this change
-
0a2f5065 was made to make sure we cannot associate a project runner to a group. This was done using
validate: true
on the association which would trigger existing validations onCi::Runner
. -
This did not work in Rails 5.1 and this spec was failing (I think with
validate: true
, the validations are now run before the association was assigned. I debugged this and found thatself.groups
was empty during the validation run).To fix this, gitlab-foss!27480 (merged) added
validates_associated :runners
on theGroup
model. This caused the massive N+1 that we see here because it would run validation on all runners of the group.
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #321827 (closed)