diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2018-11-02 19:43:07 +0000 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2018-11-02 21:38:58 +0000 |
commit | d76fdfcfdb1c815f687b01f2f7610f70bf3e378e (patch) | |
tree | ca3e926fee3c9b8fc493a2e8feeafd75a3db0ce4 | |
parent | 9e48cbf89d86e85868eb9a6496adb53d593dcacb (diff) | |
download | gitlab-ce-ce-jej/group-saml-sso-badges.tar.gz |
Add MembersPreloader to fix ActiveRecord copce-jej/group-saml-sso-badges
MembersPresentation was previously preloading records and we wanted to
extend this in
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/5807
By moving this to MembersPreloader we avoid introducing a new cop
exception that would otherwise have been needed
in EE::MembersPresentation
-rw-r--r-- | app/controllers/concerns/members_presentation.rb | 7 | ||||
-rw-r--r-- | app/models/members_preloader.rb | 16 |
2 files changed, 17 insertions, 6 deletions
diff --git a/app/controllers/concerns/members_presentation.rb b/app/controllers/concerns/members_presentation.rb index c6c3598a976..0a9d3d86245 100644 --- a/app/controllers/concerns/members_presentation.rb +++ b/app/controllers/concerns/members_presentation.rb @@ -12,12 +12,7 @@ module MembersPresentation ).fabricate! end - # rubocop: disable CodeReuse/ActiveRecord def preload_associations(members) - ActiveRecord::Associations::Preloader.new.preload(members, :user) - ActiveRecord::Associations::Preloader.new.preload(members, :source) - ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status) - ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations) + MembersPreloader.new(members).preload_all end - # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/models/members_preloader.rb b/app/models/members_preloader.rb new file mode 100644 index 00000000000..33855191ca8 --- /dev/null +++ b/app/models/members_preloader.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class MembersPreloader + attr_reader :members + + def initialize(members) + @members = members + end + + def preload_all + ActiveRecord::Associations::Preloader.new.preload(members, :user) + ActiveRecord::Associations::Preloader.new.preload(members, :source) + ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status) + ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations) + end +end |