Commit cd7b816e authored by Yorick Peterse's avatar Yorick Peterse

Allow EE offenses for the CodeReuse cops

This whitelists various EE specific offenses of the various CodeReuse
cops.
parent e652e2a7
...@@ -43,6 +43,7 @@ module KerberosSpnegoHelper ...@@ -43,6 +43,7 @@ module KerberosSpnegoHelper
headers['Www-Authenticate'] = spnego_challenge if spnego_response_token headers['Www-Authenticate'] = spnego_challenge if spnego_response_token
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_kerberos_user def find_kerberos_user
krb_principal = spnego_credentials!(spnego_token) krb_principal = spnego_credentials!(spnego_token)
return unless krb_principal return unless krb_principal
...@@ -50,6 +51,7 @@ module KerberosSpnegoHelper ...@@ -50,6 +51,7 @@ module KerberosSpnegoHelper
identity = ::Identity.with_extern_uid(:kerberos, krb_principal).take identity = ::Identity.with_extern_uid(:kerberos, krb_principal).take
identity&.user identity&.user
end end
# rubocop: enable CodeReuse/ActiveRecord
# The Kerberos backend will translate spnego_token into a Kerberos # The Kerberos backend will translate spnego_token into a Kerberos
# principal and/or provide a value for @spnego_response_token. # principal and/or provide a value for @spnego_response_token.
......
...@@ -23,6 +23,7 @@ module Search ...@@ -23,6 +23,7 @@ module Search
@projects ||= ProjectsFinder.new(current_user: current_user).execute @projects ||= ProjectsFinder.new(current_user: current_user).execute
end end
# rubocop: disable CodeReuse/ActiveRecord
def elastic_projects def elastic_projects
@elastic_projects ||= @elastic_projects ||=
if current_user&.full_private_access? if current_user&.full_private_access?
...@@ -33,6 +34,7 @@ module Search ...@@ -33,6 +34,7 @@ module Search
[] []
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def elastic_global def elastic_global
true true
......
...@@ -4,6 +4,7 @@ class Admin::GeoNodesController < Admin::ApplicationController ...@@ -4,6 +4,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
helper EE::GeoHelper helper EE::GeoHelper
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@nodes = GeoNode.all.order(:id) @nodes = GeoNode.all.order(:id)
@node = GeoNode.new @node = GeoNode.new
...@@ -12,6 +13,7 @@ class Admin::GeoNodesController < Admin::ApplicationController ...@@ -12,6 +13,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
flash_now(:alert, 'You need a different license to enable Geo replication') flash_now(:alert, 'You need a different license to enable Geo replication')
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def create def create
@node = Geo::NodeCreateService.new(geo_node_params).execute @node = Geo::NodeCreateService.new(geo_node_params).execute
......
...@@ -39,7 +39,9 @@ class Admin::PushRulesController < Admin::ApplicationController ...@@ -39,7 +39,9 @@ class Admin::PushRulesController < Admin::ApplicationController
params.require(:push_rule).permit(allowed_fields) params.require(:push_rule).permit(allowed_fields)
end end
# rubocop: disable CodeReuse/ActiveRecord
def push_rule def push_rule
@push_rule ||= PushRule.find_or_initialize_by(is_sample: true) @push_rule ||= PushRule.find_or_initialize_by(is_sample: true)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -4,6 +4,7 @@ module Boards ...@@ -4,6 +4,7 @@ module Boards
# If board parent is a project it only enumerates project members # If board parent is a project it only enumerates project members
# If board parent is a group it enumerates all members of current group, # If board parent is a group it enumerates all members of current group,
# ancestors, and descendants # ancestors, and descendants
# rubocop: disable CodeReuse/ActiveRecord
def index def index
user_ids = user_finder.execute.select(:user_id) user_ids = user_finder.execute.select(:user_id)
...@@ -11,6 +12,7 @@ module Boards ...@@ -11,6 +12,7 @@ module Boards
render json: UserSerializer.new.represent(users) render json: UserSerializer.new.represent(users)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -22,6 +22,7 @@ module EE ...@@ -22,6 +22,7 @@ module EE
) )
end end
# rubocop: disable CodeReuse/ActiveRecord
def objects_exceed_repo_limit? def objects_exceed_repo_limit?
return false unless project.size_limit_enabled? return false unless project.size_limit_enabled?
...@@ -33,5 +34,6 @@ module EE ...@@ -33,5 +34,6 @@ module EE
@exceeded_limit > 0 # rubocop:disable Gitlab/ModuleWithInstanceVariables @exceeded_limit > 0 # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -17,6 +17,7 @@ module EE ...@@ -17,6 +17,7 @@ module EE
end end
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def override def override
member = @group.members.find_by!(id: params[:id]) member = @group.members.find_by!(id: params[:id])
updated_member = ::Members::UpdateService.new(current_user, override_params) updated_member = ::Members::UpdateService.new(current_user, override_params)
...@@ -28,6 +29,7 @@ module EE ...@@ -28,6 +29,7 @@ module EE
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
protected protected
......
...@@ -6,6 +6,7 @@ module EE ...@@ -6,6 +6,7 @@ module EE
private private
# rubocop: disable CodeReuse/ActiveRecord
def set_suggested_approvers def set_suggested_approvers
if merge_request.requires_approve? if merge_request.requires_approve?
@suggested_approvers = ::Gitlab::AuthorityAnalyzer.new( # rubocop:disable Gitlab/ModuleWithInstanceVariables @suggested_approvers = ::Gitlab::AuthorityAnalyzer.new( # rubocop:disable Gitlab/ModuleWithInstanceVariables
...@@ -14,6 +15,7 @@ module EE ...@@ -14,6 +15,7 @@ module EE
).calculate(merge_request.approvals_required) ).calculate(merge_request.approvals_required)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def merge_request_params def merge_request_params
clamp_approvals_before_merge(super) clamp_approvals_before_merge(super)
......
...@@ -37,6 +37,7 @@ module EE ...@@ -37,6 +37,7 @@ module EE
# Assigning both @merge_request and @issuable like in # Assigning both @merge_request and @issuable like in
# `Projects::MergeRequests::ApplicationController`, and calling super if # `Projects::MergeRequests::ApplicationController`, and calling super if
# we don't need the extra includes requires us to disable this cop. # we don't need the extra includes requires us to disable this cop.
# rubocop: disable CodeReuse/ActiveRecord
def merge_request def merge_request
return super unless APPROVAL_RENDERING_ACTIONS.include?(action_name.to_sym) return super unless APPROVAL_RENDERING_ACTIONS.include?(action_name.to_sym)
...@@ -48,6 +49,7 @@ module EE ...@@ -48,6 +49,7 @@ module EE
.find_by!(iid: params[:id]) .find_by!(iid: params[:id])
super super
end end
# rubocop: enable CodeReuse/ActiveRecord
def define_edit_vars def define_edit_vars
super super
......
...@@ -20,6 +20,7 @@ module EE ...@@ -20,6 +20,7 @@ module EE
@metric = project.prometheus_metrics.new # rubocop:disable Gitlab/ModuleWithInstanceVariables @metric = project.prometheus_metrics.new # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
# rubocop: disable CodeReuse/ActiveRecord
def index def index
respond_to do |format| respond_to do |format|
format.json do format.json do
...@@ -34,6 +35,7 @@ module EE ...@@ -34,6 +35,7 @@ module EE
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def create def create
@metric = project.prometheus_metrics.create(metrics_params) # rubocop:disable Gitlab/ModuleWithInstanceVariables @metric = project.prometheus_metrics.create(metrics_params) # rubocop:disable Gitlab/ModuleWithInstanceVariables
......
...@@ -24,10 +24,12 @@ module EE ...@@ -24,10 +24,12 @@ module EE
private private
# rubocop: disable CodeReuse/ActiveRecord
def define_protected_env_variables def define_protected_env_variables
@protected_environments = @project.protected_environments.order(:name) @protected_environments = @project.protected_environments.order(:name)
@protected_environment = @project.protected_environments.new @protected_environment = @project.protected_environments.new
end end
# rubocop: enable CodeReuse/ActiveRecord
def assign_variables_to_gon def assign_variables_to_gon
gon.push(current_project_id: project.id) gon.push(current_project_id: project.id)
......
...@@ -28,16 +28,20 @@ class Groups::AnalyticsController < Groups::ApplicationController ...@@ -28,16 +28,20 @@ class Groups::AnalyticsController < Groups::ApplicationController
users.map { |user| data.fetch(user.id, 0) } users.map { |user| data.fetch(user.id, 0) }
end end
# rubocop: disable CodeReuse/ActiveRecord
def users def users
@users ||= @group.users.select(:id, :name, :username).reorder(:id) @users ||= @group.users.select(:id, :name, :username).reorder(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def load_events def load_events
@start_date = params[:start_date] || Date.today - 1.week @start_date = params[:start_date] || Date.today - 1.week
@events = Event.contributions @events = Event.contributions
.where("created_at > ?", @start_date) .where("created_at > ?", @start_date)
.where(project_id: @group.projects) .where(project_id: @group.projects)
end end
# rubocop: enable CodeReuse/ActiveRecord
def event_totals def event_totals
@event_totals ||= { @event_totals ||= {
......
...@@ -19,10 +19,12 @@ class Groups::AutocompleteSourcesController < Groups::ApplicationController ...@@ -19,10 +19,12 @@ class Groups::AutocompleteSourcesController < Groups::ApplicationController
@autocomplete_service = ::Groups::AutocompleteService.new(@group, current_user) @autocomplete_service = ::Groups::AutocompleteService.new(@group, current_user)
end end
# rubocop: disable CodeReuse/ActiveRecord
def target def target
case params[:type]&.downcase case params[:type]&.downcase
when 'epic' when 'epic'
EpicsFinder.new(current_user, group_id: @group.id).find_by(iid: params[:type_id]) EpicsFinder.new(current_user, group_id: @group.id).find_by(iid: params[:type_id])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -17,6 +17,7 @@ class Groups::Epics::NotesController < Groups::ApplicationController ...@@ -17,6 +17,7 @@ class Groups::Epics::NotesController < Groups::ApplicationController
end end
alias_method :awardable, :note alias_method :awardable, :note
# rubocop: disable CodeReuse/ActiveRecord
def epic def epic
@epic ||= @group.epics.find_by(iid: params[:epic_id]) @epic ||= @group.epics.find_by(iid: params[:epic_id])
...@@ -24,6 +25,7 @@ class Groups::Epics::NotesController < Groups::ApplicationController ...@@ -24,6 +25,7 @@ class Groups::Epics::NotesController < Groups::ApplicationController
@epic @epic
end end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :noteable, :epic alias_method :noteable, :epic
def finder_params def finder_params
......
...@@ -44,6 +44,7 @@ class Groups::EpicsController < Groups::ApplicationController ...@@ -44,6 +44,7 @@ class Groups::EpicsController < Groups::ApplicationController
request.format.json? request.format.json?
end end
# rubocop: disable CodeReuse/ActiveRecord
def epic def epic
@issuable = @epic ||= @group.epics.find_by(iid: params[:epic_id] || params[:id]) @issuable = @epic ||= @group.epics.find_by(iid: params[:epic_id] || params[:id])
...@@ -51,6 +52,7 @@ class Groups::EpicsController < Groups::ApplicationController ...@@ -51,6 +52,7 @@ class Groups::EpicsController < Groups::ApplicationController
@noteable = @epic @noteable = @epic
end end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :issuable, :epic alias_method :issuable, :epic
alias_method :awardable, :epic alias_method :awardable, :epic
alias_method :subscribable_resource, :epic alias_method :subscribable_resource, :epic
......
...@@ -25,10 +25,12 @@ class Groups::LdapGroupLinksController < Groups::ApplicationController ...@@ -25,10 +25,12 @@ class Groups::LdapGroupLinksController < Groups::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def destroy def destroy
@group.ldap_group_links.where(id: params[:id]).destroy_all # rubocop: disable DestroyAll @group.ldap_group_links.where(id: params[:id]).destroy_all # rubocop: disable DestroyAll
redirect_back_or_default(default: { action: 'index' }, options: { notice: 'LDAP link removed' }) redirect_back_or_default(default: { action: 'index' }, options: { notice: 'LDAP link removed' })
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -6,6 +6,7 @@ class Groups::TodosController < Groups::ApplicationController ...@@ -6,6 +6,7 @@ class Groups::TodosController < Groups::ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def issuable def issuable
strong_memoize(:epic) do strong_memoize(:epic) do
next if params[:issuable_type] != 'epic' next if params[:issuable_type] != 'epic'
...@@ -13,4 +14,5 @@ class Groups::TodosController < Groups::ApplicationController ...@@ -13,4 +14,5 @@ class Groups::TodosController < Groups::ApplicationController
@group.epics.find_by(id: params[:issuable_id]) @group.epics.find_by(id: params[:issuable_id])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -12,6 +12,7 @@ class Oauth::GeoAuthController < ActionController::Base ...@@ -12,6 +12,7 @@ class Oauth::GeoAuthController < ActionController::Base
redirect_to oauth.authorize_url(redirect_uri: oauth_geo_callback_url, state: params[:state]) redirect_to oauth.authorize_url(redirect_uri: oauth_geo_callback_url, state: params[:state])
end end
# rubocop: disable CodeReuse/ActiveRecord
def callback def callback
oauth = Gitlab::Geo::OauthSession.new(state: params[:state]) oauth = Gitlab::Geo::OauthSession.new(state: params[:state])
unless oauth.oauth_state_valid? unless oauth.oauth_state_valid?
...@@ -30,6 +31,7 @@ class Oauth::GeoAuthController < ActionController::Base ...@@ -30,6 +31,7 @@ class Oauth::GeoAuthController < ActionController::Base
invalid_credentials invalid_credentials
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def logout def logout
logout = Oauth2::LogoutTokenValidationService.new(current_user, params) logout = Oauth2::LogoutTokenValidationService.new(current_user, params)
......
...@@ -13,6 +13,7 @@ class Projects::ApproverGroupsController < Projects::ApplicationController ...@@ -13,6 +13,7 @@ class Projects::ApproverGroupsController < Projects::ApplicationController
access_denied! unless can?(current_user, :update_approvers, subject) access_denied! unless can?(current_user, :update_approvers, subject)
end end
# rubocop: disable CodeReuse/ActiveRecord
def subject def subject
@subject ||= @subject ||=
if params[:merge_request_id] if params[:merge_request_id]
...@@ -21,4 +22,5 @@ class Projects::ApproverGroupsController < Projects::ApplicationController ...@@ -21,4 +22,5 @@ class Projects::ApproverGroupsController < Projects::ApplicationController
project project
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -13,6 +13,7 @@ class Projects::ApproversController < Projects::ApplicationController ...@@ -13,6 +13,7 @@ class Projects::ApproversController < Projects::ApplicationController
access_denied! unless can?(current_user, :update_approvers, subject) access_denied! unless can?(current_user, :update_approvers, subject)
end end
# rubocop: disable CodeReuse/ActiveRecord
def subject def subject
@subject ||= @subject ||=
if params[:merge_request_id] if params[:merge_request_id]
...@@ -21,4 +22,5 @@ class Projects::ApproversController < Projects::ApplicationController ...@@ -21,4 +22,5 @@ class Projects::ApproversController < Projects::ApplicationController
project project
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -19,11 +19,13 @@ module Projects ...@@ -19,11 +19,13 @@ module Projects
render_404 if link.target != issue && link.source != issue render_404 if link.target != issue && link.source != issue
end end
# rubocop: disable CodeReuse/ActiveRecord
def issue def issue
@issue ||= @issue ||=
IssuesFinder.new(current_user, project_id: @project.id) IssuesFinder.new(current_user, project_id: @project.id)
.find_by!(iid: params[:issue_id]) .find_by!(iid: params[:issue_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def create_service def create_service
IssueLinks::CreateService.new(issue, current_user, create_params) IssueLinks::CreateService.new(issue, current_user, create_params)
......
...@@ -14,6 +14,7 @@ class Projects::PathLocksController < Projects::ApplicationController ...@@ -14,6 +14,7 @@ class Projects::PathLocksController < Projects::ApplicationController
@path_locks = @project.path_locks.page(params[:page]) @path_locks = @project.path_locks.page(params[:page])
end end
# rubocop: disable CodeReuse/ActiveRecord
def toggle def toggle
path_lock = @project.path_locks.find_by(path: params[:path]) path_lock = @project.path_locks.find_by(path: params[:path])
...@@ -27,6 +28,7 @@ class Projects::PathLocksController < Projects::ApplicationController ...@@ -27,6 +28,7 @@ class Projects::PathLocksController < Projects::ApplicationController
rescue PathLocks::UnlockService::AccessDenied, PathLocks::LockService::AccessDenied rescue PathLocks::UnlockService::AccessDenied, PathLocks::LockService::AccessDenied
access_denied! access_denied!
end end
# rubocop: enable CodeReuse/ActiveRecord
def destroy def destroy
path_lock = @project.path_locks.find(params[:id]) path_lock = @project.path_locks.find(params[:id])
......
...@@ -9,11 +9,13 @@ module Projects ...@@ -9,11 +9,13 @@ module Projects
before_action :authorize_admin_project!, except: [:notify] before_action :authorize_admin_project!, except: [:notify]
before_action :alert, only: [:update, :show, :destroy] before_action :alert, only: [:update, :show, :destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
alerts = project.prometheus_alerts.reorder(id: :asc) alerts = project.prometheus_alerts.reorder(id: :asc)
render json: serialize_as_json(alerts) render json: serialize_as_json(alerts)
end end
# rubocop: enable CodeReuse/ActiveRecord
def show def show
render json: serialize_as_json(alert) render json: serialize_as_json(alert)
...@@ -81,9 +83,11 @@ module Projects ...@@ -81,9 +83,11 @@ module Projects
PrometheusAlertSerializer.new(project: project, current_user: current_user) PrometheusAlertSerializer.new(project: project, current_user: current_user)
end end
# rubocop: disable CodeReuse/ActiveRecord
def alert def alert
@alert ||= project.prometheus_alerts.find_by(prometheus_metric_id: params[:id]) || render_404 @alert ||= project.prometheus_alerts.find_by(prometheus_metric_id: params[:id]) || render_404
end end
# rubocop: enable CodeReuse/ActiveRecord
def application def application
@application ||= alert.environment.cluster_prometheus_adapter @application ||= alert.environment.cluster_prometheus_adapter
......
...@@ -6,6 +6,7 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle ...@@ -6,6 +6,7 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
respond_to :json respond_to :json
# rubocop: disable CodeReuse/ActiveRecord
def index def index
# TODO: Move to finder or list service # TODO: Move to finder or list service
@vulnerability_feedback = @project.vulnerability_feedback.with_associations @vulnerability_feedback = @project.vulnerability_feedback.with_associations
...@@ -21,6 +22,7 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle ...@@ -21,6 +22,7 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
render json: serializer.represent(@vulnerability_feedback) render json: serializer.represent(@vulnerability_feedback)
end end
# rubocop: enable CodeReuse/ActiveRecord
def create def create
service = VulnerabilityFeedbackModule::CreateService.new(project, current_user, vulnerability_feedback_params) service = VulnerabilityFeedbackModule::CreateService.new(project, current_user, vulnerability_feedback_params)
......
...@@ -17,8 +17,10 @@ class UnsubscribesController < ApplicationController ...@@ -17,8 +17,10 @@ class UnsubscribesController < ApplicationController
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def get_user def get_user
@email = Base64.urlsafe_decode64(params[:email]) @email = Base64.urlsafe_decode64(params[:email])
User.where(email: @email).first User.where(email: @email).first
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -16,6 +16,8 @@ module Autocomplete ...@@ -16,6 +16,8 @@ module Autocomplete
@params = params @params = params
end end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/Finder
def execute def execute
project = ::Autocomplete::ProjectFinder project = ::Autocomplete::ProjectFinder
.new(current_user, params) .new(current_user, params)
...@@ -23,5 +25,7 @@ module Autocomplete ...@@ -23,5 +25,7 @@ module Autocomplete
project ? project.invited_groups : Group.none project ? project.invited_groups : Group.none
end end
# rubocop: enable CodeReuse/Finder
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -11,6 +11,7 @@ module Boards ...@@ -11,6 +11,7 @@ module Boards
private private
# rubocop: disable CodeReuse/Finder
def finder_service def finder_service
parent = @board.parent parent = @board.parent
...@@ -28,5 +29,6 @@ module Boards ...@@ -28,5 +29,6 @@ module Boards
::MilestonesFinder.new(finder_params) ::MilestonesFinder.new(finder_params)
end end
# rubocop: enable CodeReuse/Finder
end end
end end
...@@ -11,6 +11,7 @@ module Boards ...@@ -11,6 +11,7 @@ module Boards
private private
# rubocop: disable CodeReuse/Finder
def finder_service def finder_service
@finder_service ||= @finder_service ||=
if @board.parent.is_a?(Group) if @board.parent.is_a?(Group)
...@@ -19,5 +20,6 @@ module Boards ...@@ -19,5 +20,6 @@ module Boards
MembersFinder.new(@board.parent, @current_user) MembersFinder.new(@board.parent, @current_user)
end end
end end
# rubocop: enable CodeReuse/Finder
end end
end end
...@@ -20,6 +20,7 @@ module EE ...@@ -20,6 +20,7 @@ module EE
private private
# rubocop: disable CodeReuse/ActiveRecord
def by_weight(items) def by_weight(items)
return items unless weights? return items unless weights?
...@@ -31,6 +32,7 @@ module EE ...@@ -31,6 +32,7 @@ module EE
items.where(weight: params[:weight]) items.where(weight: params[:weight])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def weights? def weights?
params[:weight].present? && params[:weight] != ::Issue::WEIGHT_ALL params[:weight].present? && params[:weight] != ::Issue::WEIGHT_ALL
...@@ -57,6 +59,7 @@ module EE ...@@ -57,6 +59,7 @@ module EE
super super
end end
# rubocop: disable CodeReuse/ActiveRecord
def assignees def assignees
strong_memoize(:assignees) do strong_memoize(:assignees) do
if params[:assignee_ids] if params[:assignee_ids]
...@@ -68,5 +71,6 @@ module EE ...@@ -68,5 +71,6 @@ module EE
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -13,6 +13,7 @@ module Epics ...@@ -13,6 +13,7 @@ module Epics
@epic_id = epic_id @epic_id = epic_id
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
strong_memoize(:execute) do strong_memoize(:execute) do
Milestone.joins(issues: :epic_issue).where(epic_issues: { epic_id: epic_id }).joins( Milestone.joins(issues: :epic_issue).where(epic_issues: { epic_id: epic_id }).joins(
...@@ -28,6 +29,7 @@ module Epics ...@@ -28,6 +29,7 @@ module Epics
).pluck(*FIELDS) ).pluck(*FIELDS)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def start_date def start_date
start_date_sourcing_milestone&.slice(START_DATE_INDEX) start_date_sourcing_milestone&.slice(START_DATE_INDEX)
......
...@@ -43,14 +43,17 @@ class EpicsFinder < IssuableFinder ...@@ -43,14 +43,17 @@ class EpicsFinder < IssuableFinder
@group = group @group = group
end end
# rubocop: disable CodeReuse/ActiveRecord
def init_collection def init_collection
groups = groups_user_can_read_epics(group.self_and_descendants) groups = groups_user_can_read_epics(group.self_and_descendants)
Epic.where(group: groups) Epic.where(group: groups)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def groups_user_can_read_epics(groups) def groups_user_can_read_epics(groups)
groups = Gitlab::GroupPlansPreloader.new.preload(groups) groups = Gitlab::GroupPlansPreloader.new.preload(groups)
...@@ -58,7 +61,9 @@ class EpicsFinder < IssuableFinder ...@@ -58,7 +61,9 @@ class EpicsFinder < IssuableFinder
groups.select { |g| Ability.allowed?(current_user, :read_epic, g) } groups.select { |g| Ability.allowed?(current_user, :read_epic, g) }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_timeframe(items) def by_timeframe(items)
return items unless params[:start_date] && params[:end_date] return items unless params[:start_date] && params[:end_date]
...@@ -72,4 +77,5 @@ class EpicsFinder < IssuableFinder ...@@ -72,4 +77,5 @@ class EpicsFinder < IssuableFinder
rescue ArgumentError rescue ArgumentError
items items
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -46,6 +46,7 @@ module Geo ...@@ -46,6 +46,7 @@ module Geo
# #
# @param [Integer] batch_size used to limit the results returned # @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_file_ids ids that will be ignored from the query # @param [Array<Integer>] except_file_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: []) def find_unsynced(batch_size:, except_file_ids: [])
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -56,7 +57,9 @@ module Geo ...@@ -56,7 +57,9 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_file_ids: []) def find_migrated_local(batch_size:, except_file_ids: [])
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -67,23 +70,29 @@ module Geo ...@@ -67,23 +70,29 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_file_ids: []) def find_retryable_failed_registries(batch_size:, except_file_ids: [])
find_failed_registries find_failed_registries
.retry_due .retry_due
.where.not(file_id: except_file_ids) .where.not(file_id: except_file_ids)
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_file_ids: []) def find_retryable_synced_missing_on_primary_registries(batch_size:, except_file_ids: [])
find_synced_missing_on_primary_registries find_synced_missing_on_primary_registries
.retry_due .retry_due
.where.not(file_id: except_file_ids) .where.not(file_id: except_file_ids)
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def all def all
if selective_sync? if selective_sync?
Upload.where(group_uploads.or(project_uploads).or(other_uploads)) Upload.where(group_uploads.or(project_uploads).or(other_uploads))
...@@ -91,7 +100,9 @@ module Geo ...@@ -91,7 +100,9 @@ module Geo
Upload.all Upload.all
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def group_uploads def group_uploads
namespace_ids = namespace_ids =
if current_node.selective_sync_by_namespaces? if current_node.selective_sync_by_namespaces?
...@@ -110,6 +121,7 @@ module Geo ...@@ -110,6 +121,7 @@ module Geo
upload_table[:model_type].eq('Namespace').and(namespace_ids_in_sql) upload_table[:model_type].eq('Namespace').and(namespace_ids_in_sql)
end end
# rubocop: enable CodeReuse/ActiveRecord
def project_uploads def project_uploads
project_ids = current_node.projects.select(:id) project_ids = current_node.projects.select(:id)
...@@ -170,12 +182,15 @@ module Geo ...@@ -170,12 +182,15 @@ module Geo
fdw_find_syncable.merge(Geo::FileRegistry.failed) fdw_find_syncable.merge(Geo::FileRegistry.failed)
end end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_syncable def fdw_find_syncable
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id") fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.geo_syncable .geo_syncable
.merge(Geo::FileRegistry.attachments) .merge(Geo::FileRegistry.attachments)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced(except_file_ids:) def fdw_find_unsynced(except_file_ids:)
upload_types = Geo::FileService::DEFAULT_OBJECT_TYPES.map { |val| "'#{val}'" }.join(',') upload_types = Geo::FileService::DEFAULT_OBJECT_TYPES.map { |val| "'#{val}'" }.join(',')
...@@ -186,11 +201,13 @@ module Geo ...@@ -186,11 +201,13 @@ module Geo
.where(file_registry: { id: nil }) .where(file_registry: { id: nil })
.where.not(id: except_file_ids) .where.not(id: except_file_ids)
end end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_find_synced_missing_on_primary def fdw_find_synced_missing_on_primary
fdw_find_synced.merge(Geo::FileRegistry.missing_on_primary) fdw_find_synced.merge(Geo::FileRegistry.missing_on_primary)
end end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_all def fdw_all
if selective_sync? if selective_sync?
Geo::Fdw::Upload.where(group_uploads.or(project_uploads).or(other_uploads)) Geo::Fdw::Upload.where(group_uploads.or(project_uploads).or(other_uploads))
...@@ -198,22 +215,26 @@ module Geo ...@@ -198,22 +215,26 @@ module Geo
Geo::Fdw::Upload.all Geo::Fdw::Upload.all
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_table def fdw_table
Geo::Fdw::Upload.table_name Geo::Fdw::Upload.table_name
end end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_migrated_local(except_file_ids:) def fdw_find_migrated_local(except_file_ids:)
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id") fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.with_files_stored_remotely .with_files_stored_remotely
.merge(Geo::FileRegistry.attachments) .merge(Geo::FileRegistry.attachments)
.where.not(id: except_file_ids) .where.not(id: except_file_ids)
end end
# rubocop: enable CodeReuse/ActiveRecord
# #
# Legacy accessors (non FDW) # Legacy accessors (non FDW)
# #
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced def legacy_find_synced
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -221,7 +242,9 @@ module Geo ...@@ -221,7 +242,9 @@ module Geo
Upload Upload
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_failed def legacy_find_failed
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -229,7 +252,9 @@ module Geo ...@@ -229,7 +252,9 @@ module Geo
Upload Upload
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced(except_file_ids:) def legacy_find_unsynced(except_file_ids:)
registry_file_ids = Geo::FileRegistry.attachments.pluck(:file_id) | except_file_ids registry_file_ids = Geo::FileRegistry.attachments.pluck(:file_id) | except_file_ids
...@@ -239,7 +264,9 @@ module Geo ...@@ -239,7 +264,9 @@ module Geo
Upload Upload
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_migrated_local(except_file_ids:) def legacy_find_migrated_local(except_file_ids:)
registry_file_ids = Geo::FileRegistry.attachments.pluck(:file_id) - except_file_ids registry_file_ids = Geo::FileRegistry.attachments.pluck(:file_id) - except_file_ids
...@@ -249,7 +276,9 @@ module Geo ...@@ -249,7 +276,9 @@ module Geo
Upload Upload
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_missing_on_primary def legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -257,5 +286,6 @@ module Geo ...@@ -257,5 +286,6 @@ module Geo
Upload Upload
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -21,6 +21,7 @@ module Geo ...@@ -21,6 +21,7 @@ module Geo
# #
# @return [ActiveRecord::Relation<Geo::Fdw::Upload>] # @return [ActiveRecord::Relation<Geo::Fdw::Upload>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_project_uploads(project) def fdw_find_project_uploads(project)
fdw_table = Geo::Fdw::Upload.table_name fdw_table = Geo::Fdw::Upload.table_name
upload_type = 'file' upload_type = 'file'
...@@ -31,8 +32,10 @@ module Geo ...@@ -31,8 +32,10 @@ module Geo
AND #{fdw_table}.model_type='#{project.class.name}' AND #{fdw_table}.model_type='#{project.class.name}'
AND file_registry.file_type='#{upload_type}'") AND file_registry.file_type='#{upload_type}'")
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::FileRegistry>] # @return [ActiveRecord::Relation<Geo::FileRegistry>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_file_registries_uploads(project) def fdw_find_file_registries_uploads(project)
fdw_table = Geo::Fdw::Upload.table_name fdw_table = Geo::Fdw::Upload.table_name
upload_type = 'file' upload_type = 'file'
...@@ -43,12 +46,14 @@ module Geo ...@@ -43,12 +46,14 @@ module Geo
AND #{fdw_table}.model_type='#{project.class.name}' AND #{fdw_table}.model_type='#{project.class.name}'
AND file_registry.file_type='#{upload_type}'") AND file_registry.file_type='#{upload_type}'")
end end
# rubocop: enable CodeReuse/ActiveRecord
# #
# Legacy accessors (non FDW) # Legacy accessors (non FDW)
# #
# @return [ActiveRecord::Relation<Geo::FileRegistry>] list of file registry items # @return [ActiveRecord::Relation<Geo::FileRegistry>] list of file registry items
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_file_registries_uploads(project) def legacy_find_file_registries_uploads(project)
upload_ids = Upload.where(model_type: project.class.name, model_id: project.id).pluck(:id) upload_ids = Upload.where(model_type: project.class.name, model_id: project.id).pluck(:id)
...@@ -64,8 +69,10 @@ module Geo ...@@ -64,8 +69,10 @@ module Geo
AND file_registry.file_type='#{upload_type}' AND file_registry.file_type='#{upload_type}'
SQL SQL
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Upload>] list of upload files # @return [ActiveRecord::Relation<Upload>] list of upload files
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_project_uploads(project) def legacy_find_project_uploads(project)
file_registry_ids = legacy_find_file_registries_uploads(project).pluck(:file_id) file_registry_ids = legacy_find_file_registries_uploads(project).pluck(:file_id)
...@@ -79,5 +86,6 @@ module Geo ...@@ -79,5 +86,6 @@ module Geo
ON (file_registry.file_id = uploads.id) ON (file_registry.file_id = uploads.id)
SQL SQL
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -42,6 +42,7 @@ module Geo ...@@ -42,6 +42,7 @@ module Geo
# #
# @param [Integer] batch_size used to limit the results returned # @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_artifact_ids ids that will be ignored from the query # @param [Array<Integer>] except_artifact_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_artifact_ids: []) def find_unsynced(batch_size:, except_artifact_ids: [])
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -52,7 +53,9 @@ module Geo ...@@ -52,7 +53,9 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_artifact_ids: []) def find_migrated_local(batch_size:, except_artifact_ids: [])
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -63,27 +66,33 @@ module Geo ...@@ -63,27 +66,33 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
def syncable def syncable
all.geo_syncable all.geo_syncable
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_artifact_ids: []) def find_retryable_failed_registries(batch_size:, except_artifact_ids: [])
find_failed_registries find_failed_registries
.retry_due .retry_due
.where.not(artifact_id: except_artifact_ids) .where.not(artifact_id: except_artifact_ids)
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_artifact_ids: []) def find_retryable_synced_missing_on_primary_registries(batch_size:, except_artifact_ids: [])
find_synced_missing_on_primary_registries find_synced_missing_on_primary_registries
.retry_due .retry_due
.where.not(artifact_id: except_artifact_ids) .where.not(artifact_id: except_artifact_ids)
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def all def all
if selective_sync? if selective_sync?
Ci::JobArtifact.joins(:project).where(projects: { id: current_node.projects }) Ci::JobArtifact.joins(:project).where(projects: { id: current_node.projects })
...@@ -91,6 +100,7 @@ module Geo ...@@ -91,6 +100,7 @@ module Geo
Ci::JobArtifact.all Ci::JobArtifact.all
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def find_synced def find_synced
if use_legacy_queries? if use_legacy_queries?
...@@ -132,11 +142,14 @@ module Geo ...@@ -132,11 +142,14 @@ module Geo
# FDW accessors # FDW accessors
# #
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find def fdw_find
fdw_all.joins("INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id = #{fdw_table}.id") fdw_all.joins("INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id = #{fdw_table}.id")
.geo_syncable .geo_syncable
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced(except_artifact_ids:) def fdw_find_unsynced(except_artifact_ids:)
fdw_all.joins("LEFT OUTER JOIN job_artifact_registry fdw_all.joins("LEFT OUTER JOIN job_artifact_registry
ON job_artifact_registry.artifact_id = #{fdw_table}.id") ON job_artifact_registry.artifact_id = #{fdw_table}.id")
...@@ -144,14 +157,18 @@ module Geo ...@@ -144,14 +157,18 @@ module Geo
.where(job_artifact_registry: { artifact_id: nil }) .where(job_artifact_registry: { artifact_id: nil })
.where.not(id: except_artifact_ids) .where.not(id: except_artifact_ids)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_migrated_local(except_artifact_ids:) def fdw_find_migrated_local(except_artifact_ids:)
fdw_all.joins("INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id = #{fdw_table}.id") fdw_all.joins("INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id = #{fdw_table}.id")
.with_files_stored_remotely .with_files_stored_remotely
.where.not(id: except_artifact_ids) .where.not(id: except_artifact_ids)
.merge(Geo::JobArtifactRegistry.all) .merge(Geo::JobArtifactRegistry.all)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_all def fdw_all
if selective_sync? if selective_sync?
Geo::Fdw::Ci::JobArtifact.joins(:project).where(projects: { id: current_node.projects }) Geo::Fdw::Ci::JobArtifact.joins(:project).where(projects: { id: current_node.projects })
...@@ -159,6 +176,7 @@ module Geo ...@@ -159,6 +176,7 @@ module Geo
Geo::Fdw::Ci::JobArtifact.all Geo::Fdw::Ci::JobArtifact.all
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_table def fdw_table
Geo::Fdw::Ci::JobArtifact.table_name Geo::Fdw::Ci::JobArtifact.table_name
...@@ -168,6 +186,7 @@ module Geo ...@@ -168,6 +186,7 @@ module Geo
# Legacy accessors (non FDW) # Legacy accessors (non FDW)
# #
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced def legacy_find_synced
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -175,7 +194,9 @@ module Geo ...@@ -175,7 +194,9 @@ module Geo
Ci::JobArtifact Ci::JobArtifact
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_failed def legacy_find_failed
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -183,7 +204,9 @@ module Geo ...@@ -183,7 +204,9 @@ module Geo
Ci::JobArtifact Ci::JobArtifact
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced(except_artifact_ids:) def legacy_find_unsynced(except_artifact_ids:)
registry_artifact_ids = Geo::JobArtifactRegistry.pluck(:artifact_id) | except_artifact_ids registry_artifact_ids = Geo::JobArtifactRegistry.pluck(:artifact_id) | except_artifact_ids
...@@ -193,7 +216,9 @@ module Geo ...@@ -193,7 +216,9 @@ module Geo
Ci::JobArtifact Ci::JobArtifact
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_migrated_local(except_artifact_ids:) def legacy_find_migrated_local(except_artifact_ids:)
registry_artifact_ids = Geo::JobArtifactRegistry.pluck(:artifact_id) - except_artifact_ids registry_artifact_ids = Geo::JobArtifactRegistry.pluck(:artifact_id) - except_artifact_ids
...@@ -203,7 +228,9 @@ module Geo ...@@ -203,7 +228,9 @@ module Geo
Ci::JobArtifact Ci::JobArtifact
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_missing_on_primary def legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -211,5 +238,6 @@ module Geo ...@@ -211,5 +238,6 @@ module Geo
Ci::JobArtifact Ci::JobArtifact
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -42,6 +42,7 @@ module Geo ...@@ -42,6 +42,7 @@ module Geo
# #
# @param [Integer] batch_size used to limit the results returned # @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_file_ids ids that will be ignored from the query # @param [Array<Integer>] except_file_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: []) def find_unsynced(batch_size:, except_file_ids: [])
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -52,7 +53,9 @@ module Geo ...@@ -52,7 +53,9 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_file_ids: []) def find_migrated_local(batch_size:, except_file_ids: [])
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -63,27 +66,33 @@ module Geo ...@@ -63,27 +66,33 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
def syncable def syncable
all.geo_syncable all.geo_syncable
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_file_ids: []) def find_retryable_failed_registries(batch_size:, except_file_ids: [])
find_failed_registries find_failed_registries
.retry_due .retry_due
.where.not(file_id: except_file_ids) .where.not(file_id: except_file_ids)
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_file_ids: []) def find_retryable_synced_missing_on_primary_registries(batch_size:, except_file_ids: [])
find_synced_missing_on_primary_registries find_synced_missing_on_primary_registries
.retry_due .retry_due
.where.not(file_id: except_file_ids) .where.not(file_id: except_file_ids)
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def all def all
if selective_sync? if selective_sync?
LfsObject.joins(:projects).where(projects: { id: current_node.projects }) LfsObject.joins(:projects).where(projects: { id: current_node.projects })
...@@ -91,6 +100,7 @@ module Geo ...@@ -91,6 +100,7 @@ module Geo
LfsObject.all LfsObject.all
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def find_synced def find_synced
if use_legacy_queries? if use_legacy_queries?
...@@ -124,12 +134,15 @@ module Geo ...@@ -124,12 +134,15 @@ module Geo
# FDW accessors # FDW accessors
# #
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find def fdw_find
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id") fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.geo_syncable .geo_syncable
.merge(Geo::FileRegistry.lfs_objects) .merge(Geo::FileRegistry.lfs_objects)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced(except_file_ids:) def fdw_find_unsynced(except_file_ids:)
fdw_all.joins("LEFT OUTER JOIN file_registry fdw_all.joins("LEFT OUTER JOIN file_registry
ON file_registry.file_id = #{fdw_table}.id ON file_registry.file_id = #{fdw_table}.id
...@@ -138,13 +151,16 @@ module Geo ...@@ -138,13 +151,16 @@ module Geo
.where(file_registry: { id: nil }) .where(file_registry: { id: nil })
.where.not(id: except_file_ids) .where.not(id: except_file_ids)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_migrated_local(except_file_ids:) def fdw_find_migrated_local(except_file_ids:)
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id") fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.with_files_stored_remotely .with_files_stored_remotely
.where.not(id: except_file_ids) .where.not(id: except_file_ids)
.merge(Geo::FileRegistry.lfs_objects) .merge(Geo::FileRegistry.lfs_objects)
end end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_find_synced def fdw_find_synced
fdw_find.merge(Geo::FileRegistry.synced) fdw_find.merge(Geo::FileRegistry.synced)
...@@ -158,6 +174,7 @@ module Geo ...@@ -158,6 +174,7 @@ module Geo
fdw_find.merge(Geo::FileRegistry.failed) fdw_find.merge(Geo::FileRegistry.failed)
end end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_all def fdw_all
if selective_sync? if selective_sync?
Geo::Fdw::LfsObject.joins(:project).where(projects: { id: current_node.projects }) Geo::Fdw::LfsObject.joins(:project).where(projects: { id: current_node.projects })
...@@ -165,6 +182,7 @@ module Geo ...@@ -165,6 +182,7 @@ module Geo
Geo::Fdw::LfsObject.all Geo::Fdw::LfsObject.all
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_table def fdw_table
Geo::Fdw::LfsObject.table_name Geo::Fdw::LfsObject.table_name
...@@ -174,6 +192,7 @@ module Geo ...@@ -174,6 +192,7 @@ module Geo
# Legacy accessors (non FDW) # Legacy accessors (non FDW)
# #
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced def legacy_find_synced
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -181,7 +200,9 @@ module Geo ...@@ -181,7 +200,9 @@ module Geo
LfsObject LfsObject
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_failed def legacy_find_failed
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -189,7 +210,9 @@ module Geo ...@@ -189,7 +210,9 @@ module Geo
LfsObject LfsObject
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced(except_file_ids:) def legacy_find_unsynced(except_file_ids:)
registry_file_ids = Geo::FileRegistry.lfs_objects.pluck(:file_id) | except_file_ids registry_file_ids = Geo::FileRegistry.lfs_objects.pluck(:file_id) | except_file_ids
...@@ -199,7 +222,9 @@ module Geo ...@@ -199,7 +222,9 @@ module Geo
LfsObject LfsObject
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_migrated_local(except_file_ids:) def legacy_find_migrated_local(except_file_ids:)
registry_file_ids = Geo::FileRegistry.lfs_objects.pluck(:file_id) - except_file_ids registry_file_ids = Geo::FileRegistry.lfs_objects.pluck(:file_id) - except_file_ids
...@@ -209,7 +234,9 @@ module Geo ...@@ -209,7 +234,9 @@ module Geo
LfsObject LfsObject
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_missing_on_primary def legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
...@@ -217,5 +244,6 @@ module Geo ...@@ -217,5 +244,6 @@ module Geo
LfsObject LfsObject
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -113,6 +113,7 @@ module Geo ...@@ -113,6 +113,7 @@ module Geo
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced_projects(batch_size:) def find_unsynced_projects(batch_size:)
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -123,7 +124,9 @@ module Geo ...@@ -123,7 +124,9 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_projects_updated_recently(batch_size:) def find_projects_updated_recently(batch_size:)
relation = relation =
if use_legacy_queries? if use_legacy_queries?
...@@ -134,6 +137,7 @@ module Geo ...@@ -134,6 +137,7 @@ module Geo
relation.limit(batch_size) relation.limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
protected protected
...@@ -183,10 +187,12 @@ module Geo ...@@ -183,10 +187,12 @@ module Geo
# #
# @return [ActiveRecord::Relation<Geo::Fdw::Project>] # @return [ActiveRecord::Relation<Geo::Fdw::Project>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced_projects def fdw_find_unsynced_projects
Geo::Fdw::Project.joins("LEFT OUTER JOIN project_registry ON project_registry.project_id = #{fdw_project_table}.id") Geo::Fdw::Project.joins("LEFT OUTER JOIN project_registry ON project_registry.project_id = #{fdw_project_table}.id")
.where(project_registry: { project_id: nil }) .where(project_registry: { project_id: nil })
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] # @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_synced_wikis def fdw_find_synced_wikis
...@@ -194,14 +200,17 @@ module Geo ...@@ -194,14 +200,17 @@ module Geo
end end
# @return [ActiveRecord::Relation<Geo::Fdw::Project>] # @return [ActiveRecord::Relation<Geo::Fdw::Project>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_projects_updated_recently def fdw_find_projects_updated_recently
Geo::Fdw::Project.joins("INNER JOIN project_registry ON project_registry.project_id = #{fdw_project_table}.id") Geo::Fdw::Project.joins("INNER JOIN project_registry ON project_registry.project_id = #{fdw_project_table}.id")
.merge(Geo::ProjectRegistry.dirty) .merge(Geo::ProjectRegistry.dirty)
.merge(Geo::ProjectRegistry.retry_due) .merge(Geo::ProjectRegistry.retry_due)
end end
# rubocop: enable CodeReuse/ActiveRecord
# Find all registries that repository or wiki need verification # Find all registries that repository or wiki need verification
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_registries_to_verify(batch_size:) def fdw_find_registries_to_verify(batch_size:)
repo_condition = repo_condition =
local_repo_condition local_repo_condition
...@@ -215,6 +224,7 @@ module Geo ...@@ -215,6 +224,7 @@ module Geo
.where(repo_condition.or(wiki_condition)) .where(repo_condition.or(wiki_condition))
.limit(batch_size) .limit(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] # @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_verified_wikis def fdw_find_verified_wikis
...@@ -233,6 +243,7 @@ module Geo ...@@ -233,6 +243,7 @@ module Geo
# #
# @return [ActiveRecord::Relation<Project>] list of unsynced projects # @return [ActiveRecord::Relation<Project>] list of unsynced projects
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced_projects def legacy_find_unsynced_projects
legacy_left_outer_join_registry_ids( legacy_left_outer_join_registry_ids(
current_node.projects, current_node.projects,
...@@ -240,8 +251,10 @@ module Geo ...@@ -240,8 +251,10 @@ module Geo
Project Project
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Project>] list of projects updated recently # @return [ActiveRecord::Relation<Project>] list of projects updated recently
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_projects_updated_recently def legacy_find_projects_updated_recently
registries = Geo::ProjectRegistry.dirty.retry_due.pluck(:project_id, :last_repository_synced_at) registries = Geo::ProjectRegistry.dirty.retry_due.pluck(:project_id, :last_repository_synced_at)
return Project.none if registries.empty? return Project.none if registries.empty?
...@@ -259,6 +272,7 @@ module Geo ...@@ -259,6 +272,7 @@ module Geo
joined_relation joined_relation
end end
# rubocop: enable CodeReuse/ActiveRecord
def quote_value(value) def quote_value(value)
::Gitlab::SQL::Glob.q(value) ::Gitlab::SQL::Glob.q(value)
...@@ -270,6 +284,7 @@ module Geo ...@@ -270,6 +284,7 @@ module Geo
end end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of synced projects # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of synced projects
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_wikis def legacy_find_synced_wikis
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
current_node.projects, current_node.projects,
...@@ -277,6 +292,7 @@ module Geo ...@@ -277,6 +292,7 @@ module Geo
Project Project
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified projects # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified projects
def legacy_find_verified_repositories def legacy_find_verified_repositories
...@@ -284,6 +300,7 @@ module Geo ...@@ -284,6 +300,7 @@ module Geo
end end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified wikis # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified wikis
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_verified_wikis def legacy_find_verified_wikis
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
current_node.projects, current_node.projects,
...@@ -291,8 +308,10 @@ module Geo ...@@ -291,8 +308,10 @@ module Geo
Project Project
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Project>] list of synced projects # @return [ActiveRecord::Relation<Project>] list of synced projects
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_project_registries(project_registries) def legacy_find_project_registries(project_registries)
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
current_node.projects, current_node.projects,
...@@ -300,8 +319,10 @@ module Geo ...@@ -300,8 +319,10 @@ module Geo
Project Project
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that sync has failed # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that sync has failed
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_filtered_failed_projects(type = nil) def legacy_find_filtered_failed_projects(type = nil)
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
find_filtered_failed_project_registries(type), find_filtered_failed_project_registries(type),
...@@ -310,8 +331,10 @@ module Geo ...@@ -310,8 +331,10 @@ module Geo
foreign_key: :project_id foreign_key: :project_id
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that verification has failed # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that verification has failed
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_filtered_verification_failed_projects(type = nil) def legacy_find_filtered_verification_failed_projects(type = nil)
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
find_filtered_verification_failed_project_registries(type), find_filtered_verification_failed_project_registries(type),
...@@ -320,8 +343,10 @@ module Geo ...@@ -320,8 +343,10 @@ module Geo
foreign_key: :project_id foreign_key: :project_id
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects where there is a checksum_mismatch # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects where there is a checksum_mismatch
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_filtered_checksum_mismatch_projects(type = nil) def legacy_find_filtered_checksum_mismatch_projects(type = nil)
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
find_filtered_checksum_mismatch_project_registries(type), find_filtered_checksum_mismatch_project_registries(type),
...@@ -330,8 +355,10 @@ module Geo ...@@ -330,8 +355,10 @@ module Geo
foreign_key: :project_id foreign_key: :project_id
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_registries_to_verify(batch_size:) def legacy_find_registries_to_verify(batch_size:)
registries = Geo::ProjectRegistry registries = Geo::ProjectRegistry
.where(local_repo_condition.or(local_wiki_condition)) .where(local_repo_condition.or(local_wiki_condition))
...@@ -364,6 +391,7 @@ module Geo ...@@ -364,6 +391,7 @@ module Geo
Geo::ProjectRegistry.where(project_id: project_ids) Geo::ProjectRegistry.where(project_id: project_ids)
end end
# rubocop: enable CodeReuse/ActiveRecord
def legacy_repository_state_table def legacy_repository_state_table
::ProjectRepositoryState.arel_table ::ProjectRepositoryState.arel_table
......
...@@ -11,6 +11,7 @@ module Geo ...@@ -11,6 +11,7 @@ module Geo
# #
# We consider fully synced any project without pending actions # We consider fully synced any project without pending actions
# or failures # or failures
# rubocop: disable CodeReuse/ActiveRecord
def synced_projects def synced_projects
no_repository_resync = project_registry[:resync_repository].eq(false) no_repository_resync = project_registry[:resync_repository].eq(false)
no_repository_sync_failure = project_registry[:repository_retry_count].eq(nil) no_repository_sync_failure = project_registry[:repository_retry_count].eq(nil)
...@@ -22,11 +23,13 @@ module Geo ...@@ -22,11 +23,13 @@ module Geo
.and(repository_verified) .and(repository_verified)
).includes(project: :route).includes(project: { namespace: :route }) ).includes(project: :route).includes(project: { namespace: :route })
end end
# rubocop: enable CodeReuse/ActiveRecord
# Return any project registry which project is pending to update # Return any project registry which project is pending to update
# #
# We include here only projects that have successfully synced before. # We include here only projects that have successfully synced before.
# We exclude projects that have tried to re-sync or re-check already and had failures # We exclude projects that have tried to re-sync or re-check already and had failures
# rubocop: disable CodeReuse/ActiveRecord
def pending_projects def pending_projects
no_repository_sync_failure = project_registry[:repository_retry_count].eq(nil) no_repository_sync_failure = project_registry[:repository_retry_count].eq(nil)
repository_successfully_synced_before = project_registry[:last_repository_successful_sync_at].not_eq(nil) repository_successfully_synced_before = project_registry[:last_repository_successful_sync_at].not_eq(nil)
...@@ -42,10 +45,12 @@ module Geo ...@@ -42,10 +45,12 @@ module Geo
.and(repository_without_verification_failure_before))) .and(repository_without_verification_failure_before)))
).includes(project: :route).includes(project: { namespace: :route }) ).includes(project: :route).includes(project: { namespace: :route })
end end
# rubocop: enable CodeReuse/ActiveRecord
# Return any project registry which project has a failure # Return any project registry which project has a failure
# #
# Both types of failures are included: Synchronization and Verification # Both types of failures are included: Synchronization and Verification
# rubocop: disable CodeReuse/ActiveRecord
def failed_projects def failed_projects
repository_sync_failed = project_registry[:repository_retry_count].gt(0) repository_sync_failed = project_registry[:repository_retry_count].gt(0)
repository_verification_failed = project_registry[:last_repository_verification_failure].not_eq(nil) repository_verification_failed = project_registry[:last_repository_verification_failure].not_eq(nil)
...@@ -57,16 +62,19 @@ module Geo ...@@ -57,16 +62,19 @@ module Geo
.or(repository_checksum_mismatch) .or(repository_checksum_mismatch)
).includes(project: :route).includes(project: { namespace: :route }) ).includes(project: :route).includes(project: { namespace: :route })
end end
# rubocop: enable CodeReuse/ActiveRecord
# Return any project registry that has never been fully synced # Return any project registry that has never been fully synced
# #
# We don't include projects without a corresponding ProjectRegistry # We don't include projects without a corresponding ProjectRegistry
# for performance reasons. # for performance reasons.
# rubocop: disable CodeReuse/ActiveRecord
def never_synced_projects def never_synced_projects
Geo::ProjectRegistry.where(last_repository_successful_sync_at: nil) Geo::ProjectRegistry.where(last_repository_successful_sync_at: nil)
.includes(project: :route) .includes(project: :route)
.includes(project: { namespace: :route }) .includes(project: { namespace: :route })
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -24,6 +24,7 @@ module Geo ...@@ -24,6 +24,7 @@ module Geo
!Gitlab::Geo::Fdw.enabled? || selective_sync? !Gitlab::Geo::Fdw.enabled? || selective_sync?
end end
# rubocop: disable CodeReuse/ActiveRecord
def legacy_inner_join_registry_ids(objects, registry_ids, klass, foreign_key: :id) def legacy_inner_join_registry_ids(objects, registry_ids, klass, foreign_key: :id)
return klass.none if registry_ids.empty? return klass.none if registry_ids.empty?
...@@ -36,7 +37,9 @@ module Geo ...@@ -36,7 +37,9 @@ module Geo
joined_relation joined_relation
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_left_outer_join_registry_ids(objects, registry_ids, klass) def legacy_left_outer_join_registry_ids(objects, registry_ids, klass)
return objects if registry_ids.empty? return objects if registry_ids.empty?
...@@ -49,5 +52,6 @@ module Geo ...@@ -49,5 +52,6 @@ module Geo
joined_relation.where(registry: { registry_present: [nil, false] }) joined_relation.where(registry: { registry_present: [nil, false] })
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -4,6 +4,7 @@ module Geo ...@@ -4,6 +4,7 @@ module Geo
@shard_name = shard_name @shard_name = shard_name
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_repositories(batch_size:) def find_failed_repositories(batch_size:)
query = build_query_to_find_failed_projects(type: :repository, batch_size: batch_size) query = build_query_to_find_failed_projects(type: :repository, batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:failed_repositories, query) cte = Gitlab::SQL::CTE.new(:failed_repositories, query)
...@@ -12,7 +13,9 @@ module Geo ...@@ -12,7 +13,9 @@ module Geo
.from(cte.alias_to(projects_table)) .from(cte.alias_to(projects_table))
.order("projects.repository_retry_at ASC") .order("projects.repository_retry_at ASC")
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_wikis(batch_size:) def find_failed_wikis(batch_size:)
query = build_query_to_find_failed_projects(type: :wiki, batch_size: batch_size) query = build_query_to_find_failed_projects(type: :wiki, batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:failed_wikis, query) cte = Gitlab::SQL::CTE.new(:failed_wikis, query)
...@@ -21,7 +24,9 @@ module Geo ...@@ -21,7 +24,9 @@ module Geo
.from(cte.alias_to(projects_table)) .from(cte.alias_to(projects_table))
.order("projects.wiki_retry_at ASC") .order("projects.wiki_retry_at ASC")
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_outdated_projects(batch_size:) def find_outdated_projects(batch_size:)
query = build_query_to_find_outdated_projects(batch_size: batch_size) query = build_query_to_find_outdated_projects(batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:outdated_projects, query) cte = Gitlab::SQL::CTE.new(:outdated_projects, query)
...@@ -30,7 +35,9 @@ module Geo ...@@ -30,7 +35,9 @@ module Geo
.from(cte.alias_to(projects_table)) .from(cte.alias_to(projects_table))
.order(last_repository_updated_at_asc) .order(last_repository_updated_at_asc)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_unverified_projects(batch_size:) def find_unverified_projects(batch_size:)
relation = relation =
Project.select(:id) Project.select(:id)
...@@ -42,6 +49,7 @@ module Geo ...@@ -42,6 +49,7 @@ module Geo
relation = apply_shard_restriction(relation) if shard_name.present? relation = apply_shard_restriction(relation) if shard_name.present?
relation relation
end end
# rubocop: enable CodeReuse/ActiveRecord
def count_verified_repositories def count_verified_repositories
Project.verified_repos.count Project.verified_repos.count
...@@ -63,6 +71,7 @@ module Geo ...@@ -63,6 +71,7 @@ module Geo
attr_reader :shard_name attr_reader :shard_name
# rubocop: disable CodeReuse/ActiveRecord
def build_query_to_find_failed_projects(type:, batch_size:) def build_query_to_find_failed_projects(type:, batch_size:)
query = query =
projects_table projects_table
...@@ -74,7 +83,9 @@ module Geo ...@@ -74,7 +83,9 @@ module Geo
query = apply_shard_restriction(query) if shard_name.present? query = apply_shard_restriction(query) if shard_name.present?
query query
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def build_query_to_find_outdated_projects(batch_size:) def build_query_to_find_outdated_projects(batch_size:)
query = query =
projects_table projects_table
...@@ -86,6 +97,7 @@ module Geo ...@@ -86,6 +97,7 @@ module Geo
query = apply_shard_restriction(query) if shard_name.present? query = apply_shard_restriction(query) if shard_name.present?
query query
end end
# rubocop: enable CodeReuse/ActiveRecord
def projects_table def projects_table
Project.arel_table Project.arel_table
...@@ -124,8 +136,10 @@ module Geo ...@@ -124,8 +136,10 @@ module Geo
Gitlab::Database.nulls_last_order('projects.last_repository_updated_at', 'ASC') Gitlab::Database.nulls_last_order('projects.last_repository_updated_at', 'ASC')
end end
# rubocop: disable CodeReuse/ActiveRecord
def apply_shard_restriction(relation) def apply_shard_restriction(relation)
relation.where(projects_table[:repository_storage].eq(shard_name)) relation.where(projects_table[:repository_storage].eq(shard_name))
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -10,9 +10,11 @@ class LogFinder ...@@ -10,9 +10,11 @@ class LogFinder
@params = params @params = params
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
AuditEvent.order(id: :desc).where(conditions).page(@params[:page]).per(PER_PAGE) AuditEvent.order(id: :desc).where(conditions).page(@params[:page]).per(PER_PAGE)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -17,8 +17,10 @@ class Packages::MavenPackageFinder ...@@ -17,8 +17,10 @@ class Packages::MavenPackageFinder
private private
# rubocop: disable CodeReuse/ActiveRecord
def packages def packages
project.packages.joins(:maven_metadatum) project.packages.joins(:maven_metadatum)
.where(packages_maven_metadata: { path: path }) .where(packages_maven_metadata: { path: path })
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -17,7 +17,9 @@ class Packages::PackageFileFinder ...@@ -17,7 +17,9 @@ class Packages::PackageFileFinder
private private
# rubocop: disable CodeReuse/ActiveRecord
def package_files def package_files
package.package_files.where(file_name: file_name) package.package_files.where(file_name: file_name)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -11,6 +11,7 @@ class SoftwareLicensePoliciesFinder ...@@ -11,6 +11,7 @@ class SoftwareLicensePoliciesFinder
@project = project @project = project
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_by_name_or_id(id) def find_by_name_or_id(id)
return nil unless can?(current_user, :read_software_license_policy, project) return nil unless can?(current_user, :read_software_license_policy, project)
...@@ -20,4 +21,5 @@ class SoftwareLicensePoliciesFinder ...@@ -20,4 +21,5 @@ class SoftwareLicensePoliciesFinder
software_licenses[:name].eq(id).or(software_license_policies[:id].eq(id)) software_licenses[:name].eq(id).or(software_license_policies[:id].eq(id))
).take ).take
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -15,6 +15,7 @@ module EE ...@@ -15,6 +15,7 @@ module EE
end end
# Tries to find a matching partial first, if there is none, we try to find a matching view # Tries to find a matching partial first, if there is none, we try to find a matching view
# rubocop: disable CodeReuse/ActiveRecord
def find_ce_template(name) def find_ce_template(name)
prefixes = [] # So don't create extra [] garbage prefixes = [] # So don't create extra [] garbage
...@@ -24,6 +25,7 @@ module EE ...@@ -24,6 +25,7 @@ module EE
ce_lookup_context.find(name, prefixes, false) ce_lookup_context.find(name, prefixes, false)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def ce_lookup_context def ce_lookup_context
@ce_lookup_context ||= begin @ce_lookup_context ||= begin
......
...@@ -44,6 +44,7 @@ module EE ...@@ -44,6 +44,7 @@ module EE
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def namespaces_options_with_developer_maintainer_access(options = {}) def namespaces_options_with_developer_maintainer_access(options = {})
selected = options.delete(:selected) || :current_user selected = options.delete(:selected) || :current_user
options[:groups] = current_user.manageable_groups(include_groups_with_developer_maintainer_access: true) options[:groups] = current_user.manageable_groups(include_groups_with_developer_maintainer_access: true)
...@@ -52,5 +53,6 @@ module EE ...@@ -52,5 +53,6 @@ module EE
namespaces_options(selected, options) namespaces_options(selected, options)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -10,9 +10,11 @@ module EE ...@@ -10,9 +10,11 @@ module EE
end end
override :find_project_for_result_blob override :find_project_for_result_blob
# rubocop: disable CodeReuse/ActiveRecord
def find_project_for_result_blob(result) def find_project_for_result_blob(result)
super || ::Project.find_by(id: result['_parent']) super || ::Project.find_by(id: result['_parent'])
end end
# rubocop: enable CodeReuse/ActiveRecord
override :parse_search_result override :parse_search_result
def parse_search_result(result) def parse_search_result(result)
......
...@@ -18,6 +18,7 @@ module Emails ...@@ -18,6 +18,7 @@ module Emails
subject: subject('Mirror user changed')) subject: subject('Mirror user changed'))
end end
# rubocop: disable CodeReuse/ActiveRecord
def prometheus_alert_fired_email(project_id, user_id, alert_params) def prometheus_alert_fired_email(project_id, user_id, alert_params)
alert_metric_id = alert_params["labels"]["gitlab_alert_id"] alert_metric_id = alert_params["labels"]["gitlab_alert_id"]
...@@ -36,6 +37,7 @@ module Emails ...@@ -36,6 +37,7 @@ module Emails
mail(to: user.notification_email, subject: subject(subject_text)) mail(to: user.notification_email, subject: subject(subject_text))
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -3,10 +3,12 @@ class ClearNamespaceSharedRunnersMinutesService < BaseService ...@@ -3,10 +3,12 @@ class ClearNamespaceSharedRunnersMinutesService < BaseService
@namespace = namespace @namespace = namespace
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
NamespaceStatistics.where(namespace: @namespace).update_all( NamespaceStatistics.where(namespace: @namespace).update_all(
shared_runners_seconds: 0, shared_runners_seconds: 0,
shared_runners_seconds_last_reset: Time.now shared_runners_seconds_last_reset: Time.now
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -6,6 +6,7 @@ module CleanupApprovers ...@@ -6,6 +6,7 @@ module CleanupApprovers
private private
# rubocop: disable CodeReuse/ActiveRecord
def cleanup_approvers(target, reload: false) def cleanup_approvers(target, reload: false)
target.approvers.where.not(user_id: params[:approver_ids]).destroy_all # rubocop: disable DestroyAll target.approvers.where.not(user_id: params[:approver_ids]).destroy_all # rubocop: disable DestroyAll
target.approver_groups.where.not(group_id: params[:approver_group_ids]).destroy_all # rubocop: disable DestroyAll target.approver_groups.where.not(group_id: params[:approver_group_ids]).destroy_all # rubocop: disable DestroyAll
...@@ -19,4 +20,5 @@ module CleanupApprovers ...@@ -19,4 +20,5 @@ module CleanupApprovers
target target
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
module EE module EE
module Boards module Boards
module BaseService module BaseService
# rubocop: disable CodeReuse/ActiveRecord
def set_assignee def set_assignee
assignee = ::User.find_by(id: params.delete(:assignee_id)) assignee = ::User.find_by(id: params.delete(:assignee_id))
params.merge!(assignee: assignee) params.merge!(assignee: assignee)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def set_milestone def set_milestone
milestone_id = params[:milestone_id] milestone_id = params[:milestone_id]
...@@ -27,6 +30,7 @@ module EE ...@@ -27,6 +30,7 @@ module EE
params[:milestone_id] = milestone&.id params[:milestone_id] = milestone&.id
end end
# rubocop: enable CodeReuse/ActiveRecord
def set_labels def set_labels
labels = params.delete(:labels) labels = params.delete(:labels)
......
...@@ -22,6 +22,7 @@ module EE ...@@ -22,6 +22,7 @@ module EE
end end
override :issues_label_links override :issues_label_links
# rubocop: disable CodeReuse/ActiveRecord
def issues_label_links def issues_label_links
if has_valid_milestone? if has_valid_milestone?
super.where("issues.milestone_id = ?", board.milestone_id) super.where("issues.milestone_id = ?", board.milestone_id)
...@@ -29,9 +30,11 @@ module EE ...@@ -29,9 +30,11 @@ module EE
super super
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def all_assignee_lists def all_assignee_lists
if parent.feature_available?(:board_assignee_lists) if parent.feature_available?(:board_assignee_lists)
board.lists.assignee.where.not(user_id: nil) board.lists.assignee.where.not(user_id: nil)
...@@ -39,7 +42,9 @@ module EE ...@@ -39,7 +42,9 @@ module EE
::List.none ::List.none
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def all_milestone_lists def all_milestone_lists
if parent.feature_available?(:board_milestone_lists) if parent.feature_available?(:board_milestone_lists)
board.lists.milestone.where.not(milestone_id: nil) board.lists.milestone.where.not(milestone_id: nil)
...@@ -47,33 +52,40 @@ module EE ...@@ -47,33 +52,40 @@ module EE
::List.none ::List.none
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def without_assignees_from_lists(issues) def without_assignees_from_lists(issues)
return issues if all_assignee_lists.empty? return issues if all_assignee_lists.empty?
issues issues
.where.not(id: issues.joins(:assignees).where(users: { id: all_assignee_lists.select(:user_id) })) .where.not(id: issues.joins(:assignees).where(users: { id: all_assignee_lists.select(:user_id) }))
end end
# rubocop: enable CodeReuse/ActiveRecord
override :metadata_fields override :metadata_fields
def metadata_fields def metadata_fields
super.merge(total_weight: 'COALESCE(SUM(weight), 0)') super.merge(total_weight: 'COALESCE(SUM(weight), 0)')
end end
# rubocop: disable CodeReuse/ActiveRecord
def without_milestones_from_lists(issues) def without_milestones_from_lists(issues)
return issues if all_milestone_lists.empty? return issues if all_milestone_lists.empty?
issues.where("milestone_id NOT IN (?) OR milestone_id IS NULL", issues.where("milestone_id NOT IN (?) OR milestone_id IS NULL",
all_milestone_lists.select(:milestone_id)) all_milestone_lists.select(:milestone_id))
end end
# rubocop: enable CodeReuse/ActiveRecord
def with_assignee(issues) def with_assignee(issues)
issues.assigned_to(list.user) issues.assigned_to(list.user)
end end
# rubocop: disable CodeReuse/ActiveRecord
def with_milestone(issues) def with_milestone(issues)
issues.where(milestone_id: list.milestone_id) issues.where(milestone_id: list.milestone_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# Prevent filtering by milestone stubs # Prevent filtering by milestone stubs
# like Milestone::Upcoming, Milestone::Started etc # like Milestone::Upcoming, Milestone::Started etc
......
...@@ -4,6 +4,7 @@ module EE ...@@ -4,6 +4,7 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :execute override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
if parent.multiple_issue_boards_available? if parent.multiple_issue_boards_available?
super super
...@@ -15,13 +16,16 @@ module EE ...@@ -15,13 +16,16 @@ module EE
boards.where(id: super.first).reorder(nil) boards.where(id: super.first).reorder(nil)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
override :boards override :boards
# rubocop: disable CodeReuse/ActiveRecord
def boards def boards
super.order('LOWER(name) ASC') super.order('LOWER(name) ASC')
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -36,10 +36,12 @@ module EE ...@@ -36,10 +36,12 @@ module EE
milestones.find(params['milestone_id']) milestones.find(params['milestone_id'])
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_user(board) def find_user(board)
user_ids = user_finder(board).execute.select(:user_id) user_ids = user_finder(board).execute.select(:user_id)
::User.where(id: user_ids).find(params['assignee_id']) ::User.where(id: user_ids).find(params['assignee_id'])
end end
# rubocop: enable CodeReuse/ActiveRecord
def milestone_finder(board) def milestone_finder(board)
@milestone_finder ||= ::Boards::MilestonesFinder.new(board, current_user) @milestone_finder ||= ::Boards::MilestonesFinder.new(board, current_user)
......
...@@ -9,6 +9,7 @@ module EE ...@@ -9,6 +9,7 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :execute override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(board) def execute(board)
not_available_lists = not_available_lists =
list_type_features_availability(board).select { |_, available| !available } list_type_features_availability(board).select { |_, available| !available }
...@@ -19,6 +20,7 @@ module EE ...@@ -19,6 +20,7 @@ module EE
super super
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -23,6 +23,7 @@ module EE ...@@ -23,6 +23,7 @@ module EE
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def builds_for_shared_runner def builds_for_shared_runner
return super unless shared_runner_build_limits_feature_enabled? return super unless shared_runner_build_limits_feature_enabled?
...@@ -31,7 +32,9 @@ module EE ...@@ -31,7 +32,9 @@ module EE
.where("projects.visibility_level=? OR (#{builds_check_limit.to_sql})=1", # rubocop:disable GitlabSecurity/SqlInjection .where("projects.visibility_level=? OR (#{builds_check_limit.to_sql})=1", # rubocop:disable GitlabSecurity/SqlInjection
::Gitlab::VisibilityLevel::PUBLIC) ::Gitlab::VisibilityLevel::PUBLIC)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def builds_check_limit def builds_check_limit
all_namespaces all_namespaces
.joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id') .joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id')
...@@ -40,7 +43,9 @@ module EE ...@@ -40,7 +43,9 @@ module EE
application_shared_runners_minutes, application_shared_runners_minutes) application_shared_runners_minutes, application_shared_runners_minutes)
.select('1') .select('1')
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def all_namespaces def all_namespaces
namespaces = ::Namespace.reorder(nil).where('namespaces.id = projects.namespace_id') namespaces = ::Namespace.reorder(nil).where('namespaces.id = projects.namespace_id')
...@@ -50,6 +55,7 @@ module EE ...@@ -50,6 +55,7 @@ module EE
namespaces namespaces
end end
# rubocop: enable CodeReuse/ActiveRecord
def application_shared_runners_minutes def application_shared_runners_minutes
::Gitlab::CurrentSettings.shared_runners_minutes ::Gitlab::CurrentSettings.shared_runners_minutes
......
...@@ -27,7 +27,7 @@ module EE ...@@ -27,7 +27,7 @@ module EE
if epic_param if epic_param
EpicIssues::CreateService.new(epic_param, current_user, { target_issue: issue }).execute EpicIssues::CreateService.new(epic_param, current_user, { target_issue: issue }).execute
else else
link = EpicIssue.find_by(issue_id: issue.id) link = EpicIssue.find_by(issue_id: issue.id) # rubocop: disable CodeReuse/ActiveRecord
return unless link return unless link
......
module EE module EE
module Lfs module Lfs
module UnlockFileService module UnlockFileService
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
result = super result = super
...@@ -12,6 +13,7 @@ module EE ...@@ -12,6 +13,7 @@ module EE
result result
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
module EE module EE
module Milestones module Milestones
module PromoteService module PromoteService
# rubocop: disable CodeReuse/ActiveRecord
def update_children(group_milestone, milestone_ids) def update_children(group_milestone, milestone_ids)
boards = ::Board.where(project_id: group_project_ids, milestone_id: milestone_ids) boards = ::Board.where(project_id: group_project_ids, milestone_id: milestone_ids)
...@@ -8,6 +9,7 @@ module EE ...@@ -8,6 +9,7 @@ module EE
super super
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -6,6 +6,7 @@ module EE ...@@ -6,6 +6,7 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :execute override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(milestone) def execute(milestone)
super super
...@@ -17,6 +18,7 @@ module EE ...@@ -17,6 +18,7 @@ module EE
milestone milestone
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -50,6 +50,7 @@ module EE ...@@ -50,6 +50,7 @@ module EE
project.group&.refresh_members_authorized_projects project.group&.refresh_members_authorized_projects
end end
# rubocop: disable CodeReuse/ActiveRecord
def create_predefined_push_rule def create_predefined_push_rule
return unless project.feature_available?(:push_rules) return unless project.feature_available?(:push_rules)
...@@ -60,6 +61,7 @@ module EE ...@@ -60,6 +61,7 @@ module EE
project.push_rule = push_rule project.push_rule = push_rule
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def setup_ci_cd_project def setup_ci_cd_project
return unless ::License.feature_available?(:ci_cd_projects) return unless ::License.feature_available?(:ci_cd_projects)
......
...@@ -25,19 +25,23 @@ module EE ...@@ -25,19 +25,23 @@ module EE
raise UsersNotAccessibleError.new unless users_accessible? raise UsersNotAccessibleError.new unless users_accessible?
end end
# rubocop: disable CodeReuse/ActiveRecord
def groups_accessible? def groups_accessible?
group_ids = @merge_params.group_ids + @push_params.group_ids + @unprotect_params.group_ids # rubocop:disable Gitlab/ModuleWithInstanceVariables group_ids = @merge_params.group_ids + @push_params.group_ids + @unprotect_params.group_ids # rubocop:disable Gitlab/ModuleWithInstanceVariables
allowed_groups = @project.invited_groups.where(id: group_ids) # rubocop:disable Gitlab/ModuleWithInstanceVariables allowed_groups = @project.invited_groups.where(id: group_ids) # rubocop:disable Gitlab/ModuleWithInstanceVariables
group_ids.count == allowed_groups.count group_ids.count == allowed_groups.count
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def users_accessible? def users_accessible?
user_ids = @merge_params.user_ids + @push_params.user_ids + @unprotect_params.user_ids # rubocop:disable Gitlab/ModuleWithInstanceVariables user_ids = @merge_params.user_ids + @push_params.user_ids + @unprotect_params.user_ids # rubocop:disable Gitlab/ModuleWithInstanceVariables
allowed_users = @project.team.users.where(id: user_ids) # rubocop:disable Gitlab/ModuleWithInstanceVariables allowed_users = @project.team.users.where(id: user_ids) # rubocop:disable Gitlab/ModuleWithInstanceVariables
user_ids.count == allowed_users.count user_ids.count == allowed_users.count
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -10,6 +10,7 @@ module EE ...@@ -10,6 +10,7 @@ module EE
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def mirror_cleanup(user) def mirror_cleanup(user)
user_mirrors = ::Project.where(mirror_user: user) user_mirrors = ::Project.where(mirror_user: user)
...@@ -20,6 +21,7 @@ module EE ...@@ -20,6 +21,7 @@ module EE
::NotificationService.new.project_mirror_user_changed(new_mirror_user, user.name, mirror) ::NotificationService.new.project_mirror_user_changed(new_mirror_user, user.name, mirror)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -9,10 +9,12 @@ module EE ...@@ -9,10 +9,12 @@ module EE
super super
end end
# rubocop: disable CodeReuse/ActiveRecord
def migrate_epics def migrate_epics
user.epics.update_all(author_id: ghost_user.id) user.epics.update_all(author_id: ghost_user.id)
::Epic.where(last_edited_by_id: user.id).update_all(last_edited_by_id: ghost_user.id) ::Epic.where(last_edited_by_id: user.id).update_all(last_edited_by_id: ghost_user.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def migrate_vulnerability_feedback def migrate_vulnerability_feedback
user.vulnerability_feedback.update_all(author_id: ghost_user.id) user.vulnerability_feedback.update_all(author_id: ghost_user.id)
......
...@@ -8,6 +8,7 @@ module EpicIssues ...@@ -8,6 +8,7 @@ module EpicIssues
private private
# rubocop: disable CodeReuse/ActiveRecord
def relate_issues(referenced_issue) def relate_issues(referenced_issue)
link = EpicIssue.find_or_initialize_by(issue: referenced_issue) link = EpicIssue.find_or_initialize_by(issue: referenced_issue)
...@@ -23,6 +24,7 @@ module EpicIssues ...@@ -23,6 +24,7 @@ module EpicIssues
yield params yield params
end end
# rubocop: enable CodeReuse/ActiveRecord
def create_notes(referenced_issue, params) def create_notes(referenced_issue, params)
if params[:issue_moved] if params[:issue_moved]
......
...@@ -17,9 +17,11 @@ module Geo ...@@ -17,9 +17,11 @@ module Geo
private private
# rubocop: disable CodeReuse/ActiveRecord
def private_token def private_token
# TODO: should we ask admin user to be defined as part of configuration? # TODO: should we ask admin user to be defined as part of configuration?
@private_token ||= User.find_by(admin: true).authentication_token @private_token ||= User.find_by(admin: true).authentication_token
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -122,9 +122,11 @@ module Geo ...@@ -122,9 +122,11 @@ module Geo
false false
end end
# rubocop: disable CodeReuse/ActiveRecord
def registry def registry
@registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id) @registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def mark_sync_as_successful(missing_on_primary: false) def mark_sync_as_successful(missing_on_primary: false)
log_info("Marking #{type} sync as successful") log_info("Marking #{type} sync as successful")
...@@ -189,6 +191,7 @@ module Geo ...@@ -189,6 +191,7 @@ module Geo
@temp_repo ||= ::Repository.new(repository.full_path, repository.project, disk_path: disk_path_temp, is_wiki: repository.is_wiki) @temp_repo ||= ::Repository.new(repository.full_path, repository.project, disk_path: disk_path_temp, is_wiki: repository.is_wiki)
end end
# rubocop: disable CodeReuse/ActiveRecord
def clean_up_temporary_repository def clean_up_temporary_repository
exists = gitlab_shell.exists?(project.repository_storage, disk_path_temp + '.git') exists = gitlab_shell.exists?(project.repository_storage, disk_path_temp + '.git')
...@@ -196,6 +199,7 @@ module Geo ...@@ -196,6 +199,7 @@ module Geo
raise Gitlab::Shell::Error, "Temporary #{type} can not be removed" raise Gitlab::Shell::Error, "Temporary #{type} can not be removed"
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def set_temp_repository_as_main def set_temp_repository_as_main
log_info( log_info(
......
...@@ -47,6 +47,7 @@ module Geo ...@@ -47,6 +47,7 @@ module Geo
log_info("File download", metadata) log_info("File download", metadata)
end end
# rubocop: disable CodeReuse/ActiveRecord
def update_registry(bytes_downloaded, mark_as_synced:, missing_on_primary: false) def update_registry(bytes_downloaded, mark_as_synced:, missing_on_primary: false)
registry = registry =
if object_type.to_sym == :job_artifact if object_type.to_sym == :job_artifact
...@@ -75,6 +76,7 @@ module Geo ...@@ -75,6 +76,7 @@ module Geo
registry.save registry.save
end end
# rubocop: enable CodeReuse/ActiveRecord
def lease_key def lease_key
"file_download_service:#{object_type}:#{object_db_id}" "file_download_service:#{object_type}:#{object_db_id}"
......
...@@ -32,6 +32,7 @@ module Geo ...@@ -32,6 +32,7 @@ module Geo
private private
# rubocop: disable CodeReuse/ActiveRecord
def file_registry def file_registry
strong_memoize(:file_registry) do strong_memoize(:file_registry) do
if object_type.to_sym == :job_artifact if object_type.to_sym == :job_artifact
...@@ -41,6 +42,7 @@ module Geo ...@@ -41,6 +42,7 @@ module Geo
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def file_path def file_path
strong_memoize(:file_path) do strong_memoize(:file_path) do
...@@ -57,6 +59,7 @@ module Geo ...@@ -57,6 +59,7 @@ module Geo
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def file_uploader def file_uploader
strong_memoize(:file_uploader) do strong_memoize(:file_uploader) do
case object_type.to_s case object_type.to_s
...@@ -74,6 +77,7 @@ module Geo ...@@ -74,6 +77,7 @@ module Geo
log_error('Could not build uploader', err.message) log_error('Could not build uploader', err.message)
raise raise
end end
# rubocop: enable CodeReuse/ActiveRecord
def upload? def upload?
Geo::FileService::DEFAULT_OBJECT_TYPES.include?(object_type.to_s) Geo::FileService::DEFAULT_OBJECT_TYPES.include?(object_type.to_s)
......
...@@ -39,6 +39,7 @@ module Geo ...@@ -39,6 +39,7 @@ module Geo
private private
# rubocop: disable CodeReuse/ActiveRecord
def schedule_file_removal(uploads) def schedule_file_removal(uploads)
paths_to_remove = uploads.find_each(batch_size: BATCH_SIZE).each_with_object([]) do |upload, to_remove| paths_to_remove = uploads.find_each(batch_size: BATCH_SIZE).each_with_object([]) do |upload, to_remove|
file_path = File.join(base_dir, upload.path) file_path = File.join(base_dir, upload.path)
...@@ -52,6 +53,7 @@ module Geo ...@@ -52,6 +53,7 @@ module Geo
Geo::FileRemovalWorker.bulk_perform_async(paths_to_remove) Geo::FileRemovalWorker.bulk_perform_async(paths_to_remove)
end end
# rubocop: enable CodeReuse/ActiveRecord
def mark_for_resync! def mark_for_resync!
finder.find_file_registries_uploads(project).delete_all finder.find_file_registries_uploads(project).delete_all
......
...@@ -23,9 +23,11 @@ module Geo ...@@ -23,9 +23,11 @@ module Geo
syncs_since_gc > 0 && period_match? && housekeeping_enabled? syncs_since_gc > 0 && period_match? && housekeeping_enabled?
end end
# rubocop: disable CodeReuse/ActiveRecord
def registry def registry
@registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id) @registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def increment! def increment!
Gitlab::Metrics.measure(:geo_increment_syncs_since_gc) do Gitlab::Metrics.measure(:geo_increment_syncs_since_gc) do
......
...@@ -6,6 +6,7 @@ module Geo ...@@ -6,6 +6,7 @@ module Geo
@type = type @type = type
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
return unless Gitlab::Geo.geo_database_configured? return unless Gitlab::Geo.geo_database_configured?
return unless Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
...@@ -21,6 +22,7 @@ module Geo ...@@ -21,6 +22,7 @@ module Geo
num_updated num_updated
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -19,10 +19,12 @@ module Issues ...@@ -19,10 +19,12 @@ module Issues
Notify.issues_csv_email(user, project, csv_data, csv_builder.status).deliver_now Notify.issues_csv_email(user, project, csv_data, csv_builder.status).deliver_now
end end
# rubocop: disable CodeReuse/ActiveRecord
def csv_builder def csv_builder
@csv_builder ||= @csv_builder ||=
CsvBuilder.new(@issues.preload(:author, :assignees, :timelogs), header_to_value_hash) CsvBuilder.new(@issues.preload(:author, :assignees, :timelogs), header_to_value_hash)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
module MergeRequests module MergeRequests
class RemoveApprovalService < MergeRequests::BaseService class RemoveApprovalService < MergeRequests::BaseService
# rubocop: disable CodeReuse/ActiveRecord
def execute(merge_request) def execute(merge_request)
# paranoid protection against running wrong deletes # paranoid protection against running wrong deletes
return unless merge_request.id && current_user.id return unless merge_request.id && current_user.id
...@@ -19,6 +20,7 @@ module MergeRequests ...@@ -19,6 +20,7 @@ module MergeRequests
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -28,7 +28,7 @@ module Projects ...@@ -28,7 +28,7 @@ module Projects
def alert def alert
strong_memoize(:alert) do strong_memoize(:alert) do
metric.prometheus_alerts.find_by(project: project) metric.prometheus_alerts.find_by(project: project) # rubocop: disable CodeReuse/ActiveRecord
end end
end end
......
...@@ -34,6 +34,7 @@ module Projects ...@@ -34,6 +34,7 @@ module Projects
private private
# rubocop: disable CodeReuse/ActiveRecord
def make_sure_chat_name_created(slack_data) def make_sure_chat_name_created(slack_data)
service = project.gitlab_slack_application_service service = project.gitlab_slack_application_service
...@@ -54,6 +55,7 @@ module Projects ...@@ -54,6 +55,7 @@ module Projects
) )
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def exchange_slack_token def exchange_slack_token
Gitlab::HTTP.get(SLACK_EXCHANGE_TOKEN_URL, query: { Gitlab::HTTP.get(SLACK_EXCHANGE_TOKEN_URL, query: {
......
...@@ -3,6 +3,7 @@ module ProtectedEnvironments ...@@ -3,6 +3,7 @@ module ProtectedEnvironments
class SearchService < BaseService class SearchService < BaseService
# Returns unprotected environments filtered by name # Returns unprotected environments filtered by name
# Limited to 20 per performance reasons # Limited to 20 per performance reasons
# rubocop: disable CodeReuse/ActiveRecord
def execute(name) def execute(name)
project project
.environments .environments
...@@ -12,5 +13,6 @@ module ProtectedEnvironments ...@@ -12,5 +13,6 @@ module ProtectedEnvironments
.limit(20) .limit(20)
.pluck(:name) .pluck(:name)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -46,9 +46,11 @@ module SlashCommands ...@@ -46,9 +46,11 @@ module SlashCommands
params[:original_command] == 'help' params[:original_command] == 'help'
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_integration def find_integration
SlackIntegration.find_by(team_id: params[:team_id], alias: project_alias) SlackIntegration.find_by(team_id: params[:team_id], alias: project_alias)
end end
# rubocop: enable CodeReuse/ActiveRecord
# Splits the command # Splits the command
# '/gitlab help' => [nil, 'help'] # '/gitlab help' => [nil, 'help']
......
...@@ -8,6 +8,7 @@ module SoftwareLicensePolicies ...@@ -8,6 +8,7 @@ module SoftwareLicensePolicies
end end
# Returns the created managed license. # Returns the created managed license.
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
return error("", 403) unless can?(@current_user, :admin_software_license_policy, @project) return error("", 403) unless can?(@current_user, :admin_software_license_policy, @project)
...@@ -39,5 +40,6 @@ module SoftwareLicensePolicies ...@@ -39,5 +40,6 @@ module SoftwareLicensePolicies
success(software_license_policy: software_license_policy) success(software_license_policy: software_license_policy)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
-# rubocop: disable CodeReuse/ActiveRecord
- return unless Gitlab::CurrentSettings.should_check_namespace_plan? - return unless Gitlab::CurrentSettings.should_check_namespace_plan?
.form-group.row .form-group.row
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
%h3 Push %h3 Push
- code_push_count = @events.code_push.count - code_push_count = @events.code_push.count
- commits_count = @events.code_push.map(&:commits_count).sum - commits_count = @events.code_push.map(&:commits_count).sum # rubocop: disable CodeReuse/ActiveRecord
- person_count = @events.code_push.pluck(:author_id).uniq.count - person_count = @events.code_push.pluck(:author_id).uniq.count # rubocop: disable CodeReuse/ActiveRecord
- person_count_string = pluralize person_count, 'person' - person_count_string = pluralize person_count, 'person'
- pushes_string = _('<strong>%{pushes}</strong> pushes, more than <strong>%{commits}</strong> commits by <strong>%{people}</strong> contributors.').html_safe % { pushes: code_push_count, commits: commits_count , people: person_count_string } - pushes_string = _('<strong>%{pushes}</strong> pushes, more than <strong>%{commits}</strong> commits by <strong>%{people}</strong> contributors.').html_safe % { pushes: code_push_count, commits: commits_count , people: person_count_string }
- if code_push_count > 0 || commits_count > 0 || person_count > 0 - if code_push_count > 0 || commits_count > 0 || person_count > 0
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
%h3 Issues %h3 Issues
- issues_created_count = @events.issues.created.count - issues_created_count = @events.issues.created.count
- issues_closed_count = @events.issues.closed.pluck(:target_id).uniq.count - issues_closed_count = @events.issues.closed.pluck(:target_id).uniq.count # rubocop: disable CodeReuse/ActiveRecord
- if issues_created_count > 0 && issues_closed_count > 0 - if issues_created_count > 0 && issues_closed_count > 0
= _('<strong>%{created_count}</strong> created, <strong>%{closed_count}</strong> closed.').html_safe % { created_count: issues_created_count, closed_count: issues_closed_count } = _('<strong>%{created_count}</strong> created, <strong>%{closed_count}</strong> closed.').html_safe % { created_count: issues_created_count, closed_count: issues_closed_count }
- else - else
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
This merge request must be approved by these users. This merge request must be approved by these users.
You can override the project settings by setting your own list of approvers. You can override the project settings by setting your own list of approvers.
- skip_groups = issuable.overall_approver_groups.pluck(:group_id) - skip_groups = issuable.overall_approver_groups.pluck(:group_id) # rubocop: disable CodeReuse/ActiveRecord
= groups_select_tag('merge_request[approver_group_ids]', multiple: true, data: { skip_groups: skip_groups, all_available: true, project: issuable.target_project }, class: 'input-large') = groups_select_tag('merge_request[approver_group_ids]', multiple: true, data: { skip_groups: skip_groups, all_available: true, project: issuable.target_project }, class: 'input-large')
.form-text.text-muted .form-text.text-muted
This merge request must be approved by members of these groups. This merge request must be approved by members of these groups.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- return unless milestone.supports_weight? - return unless milestone.supports_weight?
- total_weight = milestone.issues_visible_to_user(current_user).sum(:weight) - total_weight = milestone.issues_visible_to_user(current_user).sum(:weight) # rubocop: disable CodeReuse/ActiveRecord
.block.weight .block.weight
.sidebar-collapsed-icon.has-tooltip{ title: milestone_weight_tooltip_text(total_weight), data: { container: 'body', placement: 'left' } } .sidebar-collapsed-icon.has-tooltip{ title: milestone_weight_tooltip_text(total_weight), data: { container: 'body', placement: 'left' } }
= icon('balance-scale') = icon('balance-scale')
......
class AdminEmailsWorker class AdminEmailsWorker
include ApplicationWorker include ApplicationWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(recipient_id, subject, body) def perform(recipient_id, subject, body)
recipient_list(recipient_id).pluck(:id).uniq.each do |user_id| recipient_list(recipient_id).pluck(:id).uniq.each do |user_id|
Notify.send_admin_notification(user_id, subject, body).deliver_later Notify.send_admin_notification(user_id, subject, body).deliver_later
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -5,6 +5,7 @@ class ChatNotificationWorker ...@@ -5,6 +5,7 @@ class ChatNotificationWorker
RESCHEDULE_INTERVAL = 2.seconds RESCHEDULE_INTERVAL = 2.seconds
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by(id: build_id).try do |build|
send_response(build) send_response(build)
...@@ -16,6 +17,7 @@ class ChatNotificationWorker ...@@ -16,6 +17,7 @@ class ChatNotificationWorker
# the job instead of producing an error. # the job instead of producing an error.
self.class.perform_in(RESCHEDULE_INTERVAL, build_id) self.class.perform_in(RESCHEDULE_INTERVAL, build_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def send_response(build) def send_response(build)
Gitlab::Chat::Responder.responder_for(build).try do |responder| Gitlab::Chat::Responder.responder_for(build).try do |responder|
......
...@@ -4,6 +4,7 @@ class ClearSharedRunnersMinutesWorker ...@@ -4,6 +4,7 @@ class ClearSharedRunnersMinutesWorker
include ApplicationWorker include ApplicationWorker
include CronjobQueue include CronjobQueue
# rubocop: disable CodeReuse/ActiveRecord
def perform def perform
return unless try_obtain_lease return unless try_obtain_lease
...@@ -17,6 +18,7 @@ class ClearSharedRunnersMinutesWorker ...@@ -17,6 +18,7 @@ class ClearSharedRunnersMinutesWorker
shared_runners_seconds: 0, shared_runners_seconds: 0,
shared_runners_seconds_last_reset: Time.now) shared_runners_seconds_last_reset: Time.now)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -7,6 +7,7 @@ class ClusterUpdateAppWorker ...@@ -7,6 +7,7 @@ class ClusterUpdateAppWorker
sidekiq_options retry: 3, dead: false sidekiq_options retry: 3, dead: false
# rubocop: disable CodeReuse/ActiveRecord
def perform(app_name, app_id, project_id, scheduled_time) def perform(app_name, app_id, project_id, scheduled_time)
project = Project.find_by(id: project_id) project = Project.find_by(id: project_id)
return unless project return unless project
...@@ -18,4 +19,5 @@ class ClusterUpdateAppWorker ...@@ -18,4 +19,5 @@ class ClusterUpdateAppWorker
Clusters::Applications::PrometheusUpdateService.new(app, project).execute Clusters::Applications::PrometheusUpdateService.new(app, project).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
module EE module EE
module BuildFinishedWorker module BuildFinishedWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
super super
...@@ -7,5 +8,6 @@ module EE ...@@ -7,5 +8,6 @@ module EE
ChatNotificationWorker.perform_async(build_id) if build.pipeline.chat? ChatNotificationWorker.perform_async(build_id) if build.pipeline.chat?
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -7,6 +7,7 @@ module EE ...@@ -7,6 +7,7 @@ module EE
private private
override :never_checked_project_ids override :never_checked_project_ids
# rubocop: disable CodeReuse/ActiveRecord
def never_checked_project_ids(batch_size) def never_checked_project_ids(batch_size)
return super unless ::Gitlab::Geo.secondary? return super unless ::Gitlab::Geo.secondary?
...@@ -16,8 +17,10 @@ module EE ...@@ -16,8 +17,10 @@ module EE
.where('last_wiki_synced_at < ?', 24.hours.ago) .where('last_wiki_synced_at < ?', 24.hours.ago)
.limit(batch_size).pluck(:project_id) .limit(batch_size).pluck(:project_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
override :old_checked_project_ids override :old_checked_project_ids
# rubocop: disable CodeReuse/ActiveRecord
def old_checked_project_ids(batch_size) def old_checked_project_ids(batch_size)
return super unless ::Gitlab::Geo.secondary? return super unless ::Gitlab::Geo.secondary?
...@@ -26,6 +29,7 @@ module EE ...@@ -26,6 +29,7 @@ module EE
.reorder(last_repository_check_at: :asc) .reorder(last_repository_check_at: :asc)
.limit(batch_size).pluck(:project_id) .limit(batch_size).pluck(:project_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -7,6 +7,7 @@ module EE ...@@ -7,6 +7,7 @@ module EE
private private
override :update_repository_check_status override :update_repository_check_status
# rubocop: disable CodeReuse/ActiveRecord
def update_repository_check_status(project, healthy) def update_repository_check_status(project, healthy)
return super unless ::Gitlab::Geo.secondary? return super unless ::Gitlab::Geo.secondary?
...@@ -18,6 +19,7 @@ module EE ...@@ -18,6 +19,7 @@ module EE
) )
project_registry.save! project_registry.save!
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -27,6 +27,7 @@ class ElasticBatchProjectIndexerWorker ...@@ -27,6 +27,7 @@ class ElasticBatchProjectIndexerWorker
logger.warn("#{err.message} indexing #{project.full_name} (ID=#{project.id}), trace - #{err.backtrace}") logger.warn("#{err.message} indexing #{project.full_name} (ID=#{project.id}), trace - #{err.backtrace}")
end end
# rubocop: disable CodeReuse/ActiveRecord
def build_relation(start, finish, update_index) def build_relation(start, finish, update_index)
relation = Project.includes(:index_status) relation = Project.includes(:index_status)
...@@ -40,4 +41,5 @@ class ElasticBatchProjectIndexerWorker ...@@ -40,4 +41,5 @@ class ElasticBatchProjectIndexerWorker
relation relation
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -10,14 +10,18 @@ module Geo ...@@ -10,14 +10,18 @@ module Geo
private private
# Why do we need a different `file_type` for each Uploader? Why not just use 'upload'? # Why do we need a different `file_type` for each Uploader? Why not just use 'upload'?
# rubocop: disable CodeReuse/ActiveRecord
def convert_resource_relation_to_job_args(relation) def convert_resource_relation_to_job_args(relation)
relation.pluck(:id, :uploader) relation.pluck(:id, :uploader)
.map { |id, uploader| [uploader.sub(/Uploader\z/, '').underscore, id] } .map { |id, uploader| [uploader.sub(/Uploader\z/, '').underscore, id] }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def convert_registry_relation_to_job_args(relation) def convert_registry_relation_to_job_args(relation)
relation.pluck(:file_type, :file_id) relation.pluck(:file_type, :file_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -46,13 +46,17 @@ module Geo ...@@ -46,13 +46,17 @@ module Geo
} }
end end
# rubocop: disable CodeReuse/ActiveRecord
def convert_resource_relation_to_job_args(relation) def convert_resource_relation_to_job_args(relation)
relation.pluck(:id).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] } relation.pluck(:id).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def convert_registry_relation_to_job_args(relation) def convert_registry_relation_to_job_args(relation)
relation.pluck(self.class::RESOURCE_ID_KEY).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] } relation.pluck(self.class::RESOURCE_ID_KEY).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -42,6 +42,7 @@ module Geo ...@@ -42,6 +42,7 @@ module Geo
take_batch(lfs_object_ids, attachment_ids, job_artifact_ids) take_batch(lfs_object_ids, attachment_ids, job_artifact_ids)
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local_lfs_objects_ids(batch_size:) def find_migrated_local_lfs_objects_ids(batch_size:)
return [] unless lfs_objects_object_store_enabled? return [] unless lfs_objects_object_store_enabled?
...@@ -49,7 +50,9 @@ module Geo ...@@ -49,7 +50,9 @@ module Geo
.pluck(:id) .pluck(:id)
.map { |id| ['lfs', id] } .map { |id| ['lfs', id] }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local_attachments_ids(batch_size:) def find_migrated_local_attachments_ids(batch_size:)
return [] unless attachments_object_store_enabled? return [] unless attachments_object_store_enabled?
...@@ -57,7 +60,9 @@ module Geo ...@@ -57,7 +60,9 @@ module Geo
.pluck(:uploader, :id) .pluck(:uploader, :id)
.map { |uploader, id| [uploader.sub(/Uploader\z/, '').underscore, id] } .map { |uploader, id| [uploader.sub(/Uploader\z/, '').underscore, id] }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local_job_artifacts_ids(batch_size:) def find_migrated_local_job_artifacts_ids(batch_size:)
return [] unless job_artifacts_object_store_enabled? return [] unless job_artifacts_object_store_enabled?
...@@ -65,6 +70,7 @@ module Geo ...@@ -65,6 +70,7 @@ module Geo
.pluck(:id) .pluck(:id)
.map { |id| ['job_artifact', id] } .map { |id| ['job_artifact', id] }
end end
# rubocop: enable CodeReuse/ActiveRecord
def scheduled_file_ids(file_types) def scheduled_file_ids(file_types)
file_types = Array(file_types) file_types = Array(file_types)
......
...@@ -12,6 +12,7 @@ module Geo ...@@ -12,6 +12,7 @@ module Geo
Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}" Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
end end
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, scheduled_time) def perform(project_id, scheduled_time)
registry = Geo::ProjectRegistry.find_or_initialize_by(project_id: project_id) registry = Geo::ProjectRegistry.find_or_initialize_by(project_id: project_id)
project = registry.project project = registry.project
...@@ -30,5 +31,6 @@ module Geo ...@@ -30,5 +31,6 @@ module Geo
Geo::RepositorySyncService.new(project).execute if registry.repository_sync_due?(scheduled_time) Geo::RepositorySyncService.new(project).execute if registry.repository_sync_due?(scheduled_time)
Geo::WikiSyncService.new(project).execute if registry.wiki_sync_due?(scheduled_time) Geo::WikiSyncService.new(project).execute if registry.wiki_sync_due?(scheduled_time)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -8,6 +8,7 @@ module Geo ...@@ -8,6 +8,7 @@ module Geo
LEASE_TIMEOUT = 60.minutes LEASE_TIMEOUT = 60.minutes
TRUNCATE_DELAY = 10.minutes TRUNCATE_DELAY = 10.minutes
# rubocop: disable CodeReuse/ActiveRecord
def perform def perform
return if Gitlab::Database.read_only? return if Gitlab::Database.read_only?
...@@ -34,6 +35,7 @@ module Geo ...@@ -34,6 +35,7 @@ module Geo
.each_batch { |batch| batch.delete_all } .each_batch { |batch| batch.delete_all }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def lease_timeout def lease_timeout
LEASE_TIMEOUT LEASE_TIMEOUT
......
...@@ -8,6 +8,7 @@ module Geo ...@@ -8,6 +8,7 @@ module Geo
BATCH_SIZE = 250 BATCH_SIZE = 250
LEASE_TIMEOUT = 60.minutes LEASE_TIMEOUT = 60.minutes
# rubocop: disable CodeReuse/ActiveRecord
def perform(geo_node_id) def perform(geo_node_id)
# Prevent multiple Sidekiq workers from performing repositories clean up # Prevent multiple Sidekiq workers from performing repositories clean up
try_obtain_lease do try_obtain_lease do
...@@ -23,9 +24,11 @@ module Geo ...@@ -23,9 +24,11 @@ module Geo
rescue ActiveRecord::RecordNotFound => e rescue ActiveRecord::RecordNotFound => e
log_error('Could not find Geo node, skipping repositories clean up', geo_node_id: geo_node_id, error: e) log_error('Could not find Geo node, skipping repositories clean up', geo_node_id: geo_node_id, error: e)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def clean_up_repositories(project) def clean_up_repositories(project)
# There is a possibility project does not have repository or wiki # There is a possibility project does not have repository or wiki
return true unless gitlab_shell.exists?(project.repository_storage, "#{project.disk_path}.git") return true unless gitlab_shell.exists?(project.repository_storage, "#{project.disk_path}.git")
...@@ -38,6 +41,7 @@ module Geo ...@@ -38,6 +41,7 @@ module Geo
log_error('Could not clean up repository', project_id: project.id, shard: project.repository.storage, disk_path: project.disk_path) log_error('Could not clean up repository', project_id: project.id, shard: project.repository.storage, disk_path: project.disk_path)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def lease_timeout def lease_timeout
LEASE_TIMEOUT LEASE_TIMEOUT
......
...@@ -61,22 +61,28 @@ module Geo ...@@ -61,22 +61,28 @@ module Geo
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_project_ids_not_synced(batch_size:) def find_project_ids_not_synced(batch_size:)
shard_restriction(finder.find_unsynced_projects(batch_size: batch_size)) shard_restriction(finder.find_unsynced_projects(batch_size: batch_size))
.where.not(id: scheduled_project_ids) .where.not(id: scheduled_project_ids)
.reorder(last_repository_updated_at: :desc) .reorder(last_repository_updated_at: :desc)
.pluck(:id) .pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_project_ids_updated_recently(batch_size:) def find_project_ids_updated_recently(batch_size:)
shard_restriction(finder.find_projects_updated_recently(batch_size: batch_size)) shard_restriction(finder.find_projects_updated_recently(batch_size: batch_size))
.where.not(id: scheduled_project_ids) .where.not(id: scheduled_project_ids)
.order('project_registry.last_repository_synced_at ASC NULLS FIRST, projects.last_repository_updated_at ASC') .order('project_registry.last_repository_synced_at ASC NULLS FIRST, projects.last_repository_updated_at ASC')
.pluck(:id) .pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def shard_restriction(relation) def shard_restriction(relation)
relation.where(repository_storage: shard_name) relation.where(repository_storage: shard_name)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -51,13 +51,17 @@ module Geo ...@@ -51,13 +51,17 @@ module Geo
resources + find_failed_project_ids(batch_size: remaining_capacity) resources + find_failed_project_ids(batch_size: remaining_capacity)
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_unverified_project_ids(batch_size:) def find_unverified_project_ids(batch_size:)
finder.find_unverified_projects(batch_size: batch_size).pluck(:id) finder.find_unverified_projects(batch_size: batch_size).pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_outdated_project_ids(batch_size:) def find_outdated_project_ids(batch_size:)
finder.find_outdated_projects(batch_size: batch_size).pluck(:id) finder.find_outdated_projects(batch_size: batch_size).pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def find_failed_project_ids(batch_size:) def find_failed_project_ids(batch_size:)
repositories_ids = find_failed_repositories_ids(batch_size: batch_size) repositories_ids = find_failed_repositories_ids(batch_size: batch_size)
...@@ -66,13 +70,17 @@ module Geo ...@@ -66,13 +70,17 @@ module Geo
take_batch(repositories_ids, wiki_ids, batch_size: batch_size) take_batch(repositories_ids, wiki_ids, batch_size: batch_size)
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_repositories_ids(batch_size:) def find_failed_repositories_ids(batch_size:)
finder.find_failed_repositories(batch_size: batch_size).pluck(:id) finder.find_failed_repositories(batch_size: batch_size).pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_wiki_ids(batch_size:) def find_failed_wiki_ids(batch_size:)
finder.find_failed_wikis(batch_size: batch_size).pluck(:id) finder.find_failed_wikis(batch_size: batch_size).pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -10,6 +10,7 @@ module Geo ...@@ -10,6 +10,7 @@ module Geo
attr_reader :project attr_reader :project
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id) def perform(project_id)
return unless Gitlab::Geo.primary? return unless Gitlab::Geo.primary?
...@@ -20,6 +21,7 @@ module Geo ...@@ -20,6 +21,7 @@ module Geo
Geo::RepositoryVerificationPrimaryService.new(project).execute Geo::RepositoryVerificationPrimaryService.new(project).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -24,10 +24,12 @@ module Geo ...@@ -24,10 +24,12 @@ module Geo
current_node.verification_max_capacity current_node.verification_max_capacity
end end
# rubocop: disable CodeReuse/ActiveRecord
def load_pending_resources def load_pending_resources
finder.find_registries_to_verify(batch_size: db_retrieve_batch_size) finder.find_registries_to_verify(batch_size: db_retrieve_batch_size)
.pluck(:id) .pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def schedule_job(registry_id) def schedule_job(registry_id)
job_id = Geo::RepositoryVerification::Secondary::SingleWorker.perform_async(registry_id) job_id = Geo::RepositoryVerification::Secondary::SingleWorker.perform_async(registry_id)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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