Skip to content

Fix N+1 when validating groups

Heinrich Lee Yu requested to merge 321827-fix-n+1-in-runner-validations into master

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

  1. 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 on Ci::Runner.

  2. 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 that self.groups was empty during the validation run).

    To fix this, gitlab-foss!27480 (merged) added validates_associated :runners on the Group 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

Availability and Testing

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)

Edited by Jan Provaznik

Merge request reports

Loading