Commit 91faa6ef authored by Sean McGivern's avatar Sean McGivern

Merge branch 'disable-batchloader-replace-methods' into 'master'

Disable BatchLoader replace_methods by default

See merge request gitlab-org/gitlab!71364
parents 432314e3 cac51506
...@@ -71,7 +71,7 @@ class AuditEvent < ApplicationRecord ...@@ -71,7 +71,7 @@ class AuditEvent < ApplicationRecord
end end
def lazy_author def lazy_author
BatchLoader.for(author_id).batch(replace_methods: false) do |author_ids, loader| BatchLoader.for(author_id).batch do |author_ids, loader|
User.select(:id, :name, :username).where(id: author_ids).find_each do |user| User.select(:id, :name, :username).where(id: author_ids).find_each do |user|
loader.call(user.id, user) loader.call(user.id, user)
end end
......
...@@ -133,7 +133,7 @@ class Commit ...@@ -133,7 +133,7 @@ class Commit
end end
def lazy(container, oid) def lazy(container, oid)
BatchLoader.for({ container: container, oid: oid }).batch(replace_methods: false) do |items, loader| BatchLoader.for({ container: container, oid: oid }).batch do |items, loader|
items_by_container = items.group_by { |i| i[:container] } items_by_container = items.group_by { |i| i[:container] }
items_by_container.each do |container, commit_ids| items_by_container.each do |container, commit_ids|
......
...@@ -110,7 +110,7 @@ module Avatarable ...@@ -110,7 +110,7 @@ module Avatarable
def retrieve_upload_from_batch(identifier) def retrieve_upload_from_batch(identifier)
BatchLoader.for(identifier: identifier, model: self) BatchLoader.for(identifier: identifier, model: self)
.batch(key: self.class, cache: true, replace_methods: false) do |upload_params, loader, args| .batch(key: self.class) do |upload_params, loader, args|
model_class = args[:key] model_class = args[:key]
paths = upload_params.flat_map do |params| paths = upload_params.flat_map do |params|
params[:model].upload_paths(params[:identifier]) params[:model].upload_paths(params[:identifier])
......
...@@ -1791,7 +1791,7 @@ class Project < ApplicationRecord ...@@ -1791,7 +1791,7 @@ class Project < ApplicationRecord
def open_issues_count(current_user = nil) def open_issues_count(current_user = nil)
return Projects::OpenIssuesCountService.new(self, current_user).count unless current_user.nil? return Projects::OpenIssuesCountService.new(self, current_user).count unless current_user.nil?
BatchLoader.for(self).batch(replace_methods: false) do |projects, loader| BatchLoader.for(self).batch do |projects, loader|
issues_count_per_project = ::Projects::BatchOpenIssuesCountService.new(projects).refresh_cache_and_retrieve_data issues_count_per_project = ::Projects::BatchOpenIssuesCountService.new(projects).refresh_cache_and_retrieve_data
issues_count_per_project.each do |project, count| issues_count_per_project.each do |project, count|
...@@ -2256,7 +2256,7 @@ class Project < ApplicationRecord ...@@ -2256,7 +2256,7 @@ class Project < ApplicationRecord
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def forks_count def forks_count
BatchLoader.for(self).batch(replace_methods: false) do |projects, loader| BatchLoader.for(self).batch do |projects, loader|
fork_count_per_project = ::Projects::BatchForksCountService.new(projects).refresh_cache_and_retrieve_data fork_count_per_project = ::Projects::BatchForksCountService.new(projects).refresh_cache_and_retrieve_data
fork_count_per_project.each do |project, count| fork_count_per_project.each do |project, count|
......
...@@ -83,7 +83,7 @@ module Users ...@@ -83,7 +83,7 @@ module Users
end end
def lazy_user_availability(user) def lazy_user_availability(user)
BatchLoader.for(user.id).batch(replace_methods: false) do |user_ids, loader| BatchLoader.for(user.id).batch do |user_ids, loader|
user_ids.each_slice(1_000) do |sliced_user_ids| user_ids.each_slice(1_000) do |sliced_user_ids|
UserStatus UserStatus
.select(:user_id, :availability) .select(:user_id, :availability)
......
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.config.middleware.use(BatchLoader::Middleware) Rails.application.config.middleware.use(BatchLoader::Middleware)
# Disables replace_methods by default.
# See https://github.com/exAspArk/batch-loader#replacing-methods for more information.
module BatchLoaderWithoutMethodReplacementByDefault
def batch(replace_methods: false, **kw_args, &batch_block)
super
end
end
BatchLoader.prepend(BatchLoaderWithoutMethodReplacementByDefault)
...@@ -47,7 +47,7 @@ module EE ...@@ -47,7 +47,7 @@ module EE
def lazy_entity def lazy_entity
BatchLoader.for(entity_id) BatchLoader.for(entity_id)
.batch( .batch(
key: entity_type, default_value: ::Gitlab::Audit::NullEntity.new, replace_methods: false key: entity_type, default_value: ::Gitlab::Audit::NullEntity.new
) do |ids, loader, args| ) do |ids, loader, args|
model = Object.const_get(args[:key], false) model = Object.const_get(args[:key], false)
model.where(id: ids).find_each { |record| loader.call(record.id, record) } model.where(id: ids).find_each { |record| loader.call(record.id, record) }
......
...@@ -153,7 +153,7 @@ module Vulnerabilities ...@@ -153,7 +153,7 @@ module Vulnerabilities
end end
def load_feedback def load_feedback
BatchLoader.for(finding_key).batch(replace_methods: false) do |finding_keys, loader| BatchLoader.for(finding_key).batch do |finding_keys, loader|
project_ids = finding_keys.map { |key| key[:project_id] } project_ids = finding_keys.map { |key| key[:project_id] }
categories = finding_keys.map { |key| key[:category] } categories = finding_keys.map { |key| key[:category] }
fingerprints = finding_keys.map { |key| key[:project_fingerprint] } fingerprints = finding_keys.map { |key| key[:project_fingerprint] }
......
...@@ -190,7 +190,7 @@ module EE ...@@ -190,7 +190,7 @@ module EE
scope :without_uuid, -> { where(uuid: nil) } scope :without_uuid, -> { where(uuid: nil) }
def feedback def feedback
BatchLoader.for(finding_key).batch(replace_methods: false) do |finding_keys, loader| BatchLoader.for(finding_key).batch do |finding_keys, loader|
project_ids = finding_keys.map { |key| key[:project_id] } project_ids = finding_keys.map { |key| key[:project_id] }
categories = finding_keys.map { |key| key[:category] } categories = finding_keys.map { |key| key[:category] }
fingerprints = finding_keys.map { |key| key[:project_fingerprint] } fingerprints = finding_keys.map { |key| key[:project_fingerprint] }
......
...@@ -24,7 +24,7 @@ module API ...@@ -24,7 +24,7 @@ module API
# entity according to the current top-level entity options, such # entity according to the current top-level entity options, such
# as the current_user. # as the current_user.
def lazy_issuable_metadata def lazy_issuable_metadata
BatchLoader.for(object).batch(key: [current_user, :issuable_metadata], replace_methods: false) do |models, loader, args| BatchLoader.for(object).batch(key: [current_user, :issuable_metadata]) do |models, loader, args|
current_user = args[:key].first current_user = args[:key].first
issuable_metadata = Gitlab::IssuableMetadata.new(current_user, models) issuable_metadata = Gitlab::IssuableMetadata.new(current_user, models)
......
...@@ -38,7 +38,7 @@ module Gitlab ...@@ -38,7 +38,7 @@ module Gitlab
end end
def vulnerability_finding def vulnerability_finding
BatchLoader.for(finding_key).batch(replace_methods: false) do |finding_keys, loader| BatchLoader.for(finding_key).batch do |finding_keys, loader|
project_ids = finding_keys.map { |key| key[:project_id] } project_ids = finding_keys.map { |key| key[:project_id] }
categories = finding_keys.map { |key| key[:category] } categories = finding_keys.map { |key| key[:category] }
fingerprints = finding_keys.map { |key| key[:project_fingerprint] } fingerprints = finding_keys.map { |key| key[:project_fingerprint] }
......
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