Commit d76fdfcf authored by James Edwards-Jones's avatar James Edwards-Jones

Add MembersPreloader to fix ActiveRecord cop

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
parent 9e48cbf8
......@@ -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
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment