summaryrefslogtreecommitdiff
path: root/app/models/members_preloader.rb
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-11-02 19:43:07 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-11-02 21:38:58 +0000
commitd76fdfcfdb1c815f687b01f2f7610f70bf3e378e (patch)
treeca3e926fee3c9b8fc493a2e8feeafd75a3db0ce4 /app/models/members_preloader.rb
parent9e48cbf89d86e85868eb9a6496adb53d593dcacb (diff)
downloadgitlab-ce-d76fdfcfdb1c815f687b01f2f7610f70bf3e378e.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
Diffstat (limited to 'app/models/members_preloader.rb')
-rw-r--r--app/models/members_preloader.rb16
1 files changed, 16 insertions, 0 deletions
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