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)
......
...@@ -14,6 +14,7 @@ module Geo ...@@ -14,6 +14,7 @@ module Geo
delegate :project, to: :registry delegate :project, to: :registry
# rubocop: disable CodeReuse/ActiveRecord
def perform(registry_id) def perform(registry_id)
return unless Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
...@@ -25,6 +26,7 @@ module Geo ...@@ -25,6 +26,7 @@ module Geo
verify_checksum(:wiki) verify_checksum(:wiki)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -107,9 +107,11 @@ module Geo ...@@ -107,9 +107,11 @@ module Geo
(Time.now.utc - start_time) >= run_time (Time.now.utc - start_time) >= run_time
end end
# rubocop: disable CodeReuse/ActiveRecord
def take_batch(*arrays, batch_size: db_retrieve_batch_size) def take_batch(*arrays, batch_size: db_retrieve_batch_size)
interleave(*arrays).uniq.compact.take(batch_size) interleave(*arrays).uniq.compact.take(batch_size)
end end
# rubocop: enable CodeReuse/ActiveRecord
# Combines the elements of multiple, arbitrary-length arrays into a single array. # Combines the elements of multiple, arbitrary-length arrays into a single array.
# #
......
class LdapGroupSyncWorker class LdapGroupSyncWorker
include ApplicationWorker include ApplicationWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(group_ids, provider = nil) def perform(group_ids, provider = nil)
return unless Gitlab::Auth::LDAP::Config.group_sync_enabled? return unless Gitlab::Auth::LDAP::Config.group_sync_enabled?
...@@ -14,6 +15,7 @@ class LdapGroupSyncWorker ...@@ -14,6 +15,7 @@ class LdapGroupSyncWorker
sync_groups(groups) sync_groups(groups)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def sync_groups(groups, proxy: nil) def sync_groups(groups, proxy: nil)
groups.each { |group| sync_group(group, proxy: proxy) } groups.each { |group| sync_group(group, proxy: proxy) }
......
...@@ -2,6 +2,7 @@ class LdapSyncWorker ...@@ -2,6 +2,7 @@ class LdapSyncWorker
include ApplicationWorker include ApplicationWorker
include CronjobQueue include CronjobQueue
# rubocop: disable CodeReuse/ActiveRecord
def perform def perform
return unless Gitlab::Auth::LDAP::Config.group_sync_enabled? return unless Gitlab::Auth::LDAP::Config.group_sync_enabled?
...@@ -13,4 +14,5 @@ class LdapSyncWorker ...@@ -13,4 +14,5 @@ class LdapSyncWorker
Gitlab::Auth::LDAP::Access.allowed?(ldap_user, update_ldap_group_links_synchronously: true) Gitlab::Auth::LDAP::Access.allowed?(ldap_user, update_ldap_group_links_synchronously: true)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -2,8 +2,10 @@ class ProjectImportScheduleWorker ...@@ -2,8 +2,10 @@ class ProjectImportScheduleWorker
include ApplicationWorker include ApplicationWorker
prepend WaitableWorker prepend WaitableWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id) def perform(project_id)
project = Project.find_by(id: project_id) project = Project.find_by(id: project_id)
project&.import_schedule project&.import_schedule
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -15,6 +15,7 @@ class UpdateAllMirrorsWorker ...@@ -15,6 +15,7 @@ class UpdateAllMirrorsWorker
cancel_lease(lease_uuid) cancel_lease(lease_uuid)
end end
# rubocop: disable CodeReuse/ActiveRecord
def schedule_mirrors! def schedule_mirrors!
capacity = Gitlab::Mirror.available_capacity capacity = Gitlab::Mirror.available_capacity
...@@ -42,6 +43,7 @@ class UpdateAllMirrorsWorker ...@@ -42,6 +43,7 @@ class UpdateAllMirrorsWorker
ProjectImportScheduleWorker.bulk_perform_and_wait(all_project_ids.map { |id| [id] }, timeout: SCHEDULE_WAIT_TIMEOUT.to_i) ProjectImportScheduleWorker.bulk_perform_and_wait(all_project_ids.map { |id| [id] }, timeout: SCHEDULE_WAIT_TIMEOUT.to_i)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
...@@ -53,6 +55,7 @@ class UpdateAllMirrorsWorker ...@@ -53,6 +55,7 @@ class UpdateAllMirrorsWorker
::Gitlab::ExclusiveLease.cancel(LEASE_KEY, uuid) ::Gitlab::ExclusiveLease.cancel(LEASE_KEY, uuid)
end end
# rubocop: disable CodeReuse/ActiveRecord
def pull_mirrors_batch(freeze_at:, batch_size:, offset_at: nil) def pull_mirrors_batch(freeze_at:, batch_size:, offset_at: nil)
relation = Project relation = Project
.mirrors_to_sync(freeze_at) .mirrors_to_sync(freeze_at)
...@@ -64,4 +67,5 @@ class UpdateAllMirrorsWorker ...@@ -64,4 +67,5 @@ class UpdateAllMirrorsWorker
relation relation
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -18,9 +18,11 @@ module API ...@@ -18,9 +18,11 @@ module API
authorize!(:admin_epic, epic) authorize!(:admin_epic, epic)
end end
# rubocop: disable CodeReuse/ActiveRecord
def epic def epic
@epic ||= user_group.epics.find_by(iid: params[:epic_iid]) @epic ||= user_group.epics.find_by(iid: params[:epic_iid])
end end
# rubocop: enable CodeReuse/ActiveRecord
def link def link
@link ||= epic.epic_issues.find(params[:epic_issue_id]) @link ||= epic.epic_issues.find(params[:epic_issue_id])
...@@ -81,6 +83,7 @@ module API ...@@ -81,6 +83,7 @@ module API
params do params do
requires :epic_iid, type: Integer, desc: 'The iid of the epic' requires :epic_iid, type: Integer, desc: 'The iid of the epic'
end end
# rubocop: disable CodeReuse/ActiveRecord
post ':id/(-/)epics/:epic_iid/issues/:issue_id' do post ':id/(-/)epics/:epic_iid/issues/:issue_id' do
authorize_can_admin! authorize_can_admin!
...@@ -98,6 +101,7 @@ module API ...@@ -98,6 +101,7 @@ module API
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Remove an issue from the epic' do desc 'Remove an issue from the epic' do
success EE::API::Entities::EpicIssueLink success EE::API::Entities::EpicIssueLink
......
...@@ -26,10 +26,13 @@ module API ...@@ -26,10 +26,13 @@ module API
authorize!(:destroy_epic, epic) authorize!(:destroy_epic, epic)
end end
# rubocop: disable CodeReuse/ActiveRecord
def epic def epic
@epic ||= user_group.epics.find_by(iid: params[:epic_iid]) @epic ||= user_group.epics.find_by(iid: params[:epic_iid])
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_epics(args = {}) def find_epics(args = {})
args = declared_params.merge(args) args = declared_params.merge(args)
args[:label_name] = args.delete(:labels) args[:label_name] = args.delete(:labels)
...@@ -38,6 +41,7 @@ module API ...@@ -38,6 +41,7 @@ module API
epics.reorder(args[:order_by] => args[:sort]) epics.reorder(args[:order_by] => args[:sort])
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
params do params do
......
...@@ -29,6 +29,7 @@ module API ...@@ -29,6 +29,7 @@ module API
requires :target_project_id, type: String, desc: 'The ID of the target project' requires :target_project_id, type: String, desc: 'The ID of the target project'
requires :target_issue_iid, type: Integer, desc: 'The IID of the target issue' requires :target_issue_iid, type: Integer, desc: 'The IID of the target issue'
end end
# rubocop: disable CodeReuse/ActiveRecord
post ':id/issues/:issue_iid/links' do post ':id/issues/:issue_iid/links' do
source_issue = find_project_issue(params[:issue_iid]) source_issue = find_project_issue(params[:issue_iid])
target_issue = find_project_issue(declared_params[:target_issue_iid], target_issue = find_project_issue(declared_params[:target_issue_iid],
...@@ -48,6 +49,7 @@ module API ...@@ -48,6 +49,7 @@ module API
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Remove issues relation' do desc 'Remove issues relation' do
success EE::API::Entities::IssueLink success EE::API::Entities::IssueLink
......
...@@ -31,6 +31,7 @@ module API ...@@ -31,6 +31,7 @@ module API
params do params do
requires 'cn', type: String, desc: 'The CN of a LDAP group' requires 'cn', type: String, desc: 'The CN of a LDAP group'
end end
# rubocop: disable CodeReuse/ActiveRecord
delete ":id/ldap_group_links/:cn" do delete ":id/ldap_group_links/:cn" do
group = find_group(params[:id]) group = find_group(params[:id])
authorize! :admin_group, group authorize! :admin_group, group
...@@ -43,12 +44,14 @@ module API ...@@ -43,12 +44,14 @@ module API
render_api_error!('Linked LDAP group not found', 404) render_api_error!('Linked LDAP group not found', 404)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Remove a linked LDAP group from group' desc 'Remove a linked LDAP group from group'
params do params do
requires 'cn', type: String, desc: 'The CN of a LDAP group' requires 'cn', type: String, desc: 'The CN of a LDAP group'
requires 'provider', type: String, desc: 'The LDAP provider for this LDAP group' requires 'provider', type: String, desc: 'The LDAP provider for this LDAP group'
end end
# rubocop: disable CodeReuse/ActiveRecord
delete ":id/ldap_group_links/:provider/:cn" do delete ":id/ldap_group_links/:provider/:cn" do
group = find_group(params[:id]) group = find_group(params[:id])
authorize! :admin_group, group authorize! :admin_group, group
...@@ -61,6 +64,7 @@ module API ...@@ -61,6 +64,7 @@ module API
render_api_error!('Linked LDAP group not found', 404) render_api_error!('Linked LDAP group not found', 404)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -87,6 +87,7 @@ module API ...@@ -87,6 +87,7 @@ module API
values: %w(approved blacklisted), values: %w(approved blacklisted),
desc: 'The approval status of the license. "blacklisted" or "approved".' desc: 'The approval status of the license. "blacklisted" or "approved".'
end end
# rubocop: disable CodeReuse/ActiveRecord
patch ':id/managed_licenses/:managed_license_id', requirements: { managed_license_id: /.*/ } do patch ':id/managed_licenses/:managed_license_id', requirements: { managed_license_id: /.*/ } do
authorize_can_admin! authorize_can_admin!
break not_found!('SoftwareLicensePolicy') unless software_license_policy break not_found!('SoftwareLicensePolicy') unless software_license_policy
...@@ -103,6 +104,7 @@ module API ...@@ -103,6 +104,7 @@ module API
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing software license policy from a project' do desc 'Delete an existing software license policy from a project' do
success Entities::ManagedLicense success Entities::ManagedLicense
......
...@@ -36,28 +36,34 @@ module API ...@@ -36,28 +36,34 @@ module API
project project
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_requests def find_merge_requests
merge_requests = authorized_merge_requests.reorder(updated_at: :desc).preload(:target_project) merge_requests = authorized_merge_requests.reorder(updated_at: :desc).preload(:target_project)
merge_requests = paginate(merge_requests) merge_requests = paginate(merge_requests)
merge_requests.select { |mr| licensed_project?(mr.target_project) } merge_requests.select { |mr| licensed_project?(mr.target_project) }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_request_with_access(id, access_level = :read_merge_request) def find_merge_request_with_access(id, access_level = :read_merge_request)
merge_request = authorized_merge_requests.find_by(id: id) merge_request = authorized_merge_requests.find_by(id: id)
not_found! unless can?(current_user, access_level, merge_request) not_found! unless can?(current_user, access_level, merge_request)
merge_request merge_request
end end
# rubocop: enable CodeReuse/ActiveRecord
def authorized_merge_requests def authorized_merge_requests
MergeRequestsFinder.new(current_user, authorized_only: true).execute MergeRequestsFinder.new(current_user, authorized_only: true).execute
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_notes(noteable) def find_notes(noteable)
# They're not presented on Jira Dev Panel ATM. A comments count with a # They're not presented on Jira Dev Panel ATM. A comments count with a
# redirect link is presented. # redirect link is presented.
notes = paginate(noteable.notes.user.reorder(nil)) notes = paginate(noteable.notes.user.reorder(nil))
notes.reject { |n| n.cross_reference_not_visible_for?(current_user) } notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
end end
# rubocop: enable CodeReuse/ActiveRecord
def licensed_project?(project) def licensed_project?(project)
project.feature_available?(JIRA_DEV_PANEL_FEATURE) project.feature_available?(JIRA_DEV_PANEL_FEATURE)
...@@ -80,6 +86,7 @@ module API ...@@ -80,6 +86,7 @@ module API
params do params do
use :pagination use :pagination
end end
# rubocop: disable CodeReuse/ActiveRecord
get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do
namespace = Namespace.find_by_full_path(params[:namespace]) namespace = Namespace.find_by_full_path(params[:namespace])
not_found!('Namespace') unless namespace not_found!('Namespace') unless namespace
...@@ -89,6 +96,7 @@ module API ...@@ -89,6 +96,7 @@ module API
projects = ::Kaminari.paginate_array(projects) projects = ::Kaminari.paginate_array(projects)
present paginate(projects), with: ::API::Github::Entities::Repository present paginate(projects), with: ::API::Github::Entities::Repository
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
# Jira dev panel integration weirdly requests for "/-/jira/pulls" instead # Jira dev panel integration weirdly requests for "/-/jira/pulls" instead
......
...@@ -39,6 +39,7 @@ module EE ...@@ -39,6 +39,7 @@ module EE
end end
# Overrides API::BoardsResponses authorize_list_type_resource! # Overrides API::BoardsResponses authorize_list_type_resource!
# rubocop: disable CodeReuse/ActiveRecord
def authorize_list_type_resource! def authorize_list_type_resource!
if params[:label_id] && !available_labels_for(board_parent).exists?(params[:label_id]) if params[:label_id] && !available_labels_for(board_parent).exists?(params[:label_id])
render_api_error!({ error: 'Label not found!' }, 400) render_api_error!({ error: 'Label not found!' }, 400)
...@@ -60,6 +61,7 @@ module EE ...@@ -60,6 +61,7 @@ module EE
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Overrides API::BoardsResponses list_creation_params # Overrides API::BoardsResponses list_creation_params
params :list_creation_params do params :list_creation_params do
......
...@@ -5,9 +5,11 @@ module EE ...@@ -5,9 +5,11 @@ module EE
prepended do prepended do
helpers do helpers do
# rubocop: disable CodeReuse/ActiveRecord
def epic def epic
@epic ||= user_group.epics.find_by(iid: params[:epic_iid]) @epic ||= user_group.epics.find_by(iid: params[:epic_iid])
end end
# rubocop: enable CodeReuse/ActiveRecord
def authorize_can_read! def authorize_can_read!
authorize!(:read_epic, epic) authorize!(:read_epic, epic)
......
...@@ -36,9 +36,11 @@ module EE ...@@ -36,9 +36,11 @@ module EE
) )
end end
# rubocop: disable CodeReuse/ActiveRecord
def parent_records(parent, ids) def parent_records(parent, ids)
parent.epics.where(iid: ids.to_a) parent.epics.where(iid: ids.to_a)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -2,6 +2,7 @@ module EE ...@@ -2,6 +2,7 @@ module EE
module Banzai module Banzai
module ReferenceParser module ReferenceParser
module EpicParser module EpicParser
# rubocop: disable CodeReuse/ActiveRecord
def records_for_nodes(nodes) def records_for_nodes(nodes)
@epics_for_nodes ||= grouped_objects_for_nodes( @epics_for_nodes ||= grouped_objects_for_nodes(
nodes, nodes,
...@@ -12,6 +13,7 @@ module EE ...@@ -12,6 +13,7 @@ module EE
self.class.data_attribute self.class.data_attribute
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -36,6 +36,7 @@ module EE ...@@ -36,6 +36,7 @@ module EE
end end
# Add ssh keys that are in LDAP but not in GitLab # Add ssh keys that are in LDAP but not in GitLab
# rubocop: disable CodeReuse/ActiveRecord
def add_new_ssh_keys def add_new_ssh_keys
keys = ldap_user.ssh_keys - user.keys.ldap.pluck(:key) keys = ldap_user.ssh_keys - user.keys.ldap.pluck(:key)
...@@ -50,8 +51,10 @@ module EE ...@@ -50,8 +51,10 @@ module EE
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Remove ssh keys that do not exist in LDAP any more # Remove ssh keys that do not exist in LDAP any more
# rubocop: disable CodeReuse/ActiveRecord
def remove_old_ssh_keys def remove_old_ssh_keys
keys = user.keys.ldap.where.not(key: ldap_user.ssh_keys) keys = user.keys.ldap.where.not(key: ldap_user.ssh_keys)
...@@ -63,8 +66,10 @@ module EE ...@@ -63,8 +66,10 @@ module EE
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Update user Kerberos identity with Kerberos principal name from Active Directory # Update user Kerberos identity with Kerberos principal name from Active Directory
# rubocop: disable CodeReuse/ActiveRecord
def update_kerberos_identity def update_kerberos_identity
# there can be only one Kerberos identity in GitLab; if the user has a Kerberos identity in AD, # there can be only one Kerberos identity in GitLab; if the user has a Kerberos identity in AD,
# replace any existing Kerberos identity for the user # replace any existing Kerberos identity for the user
...@@ -80,6 +85,7 @@ module EE ...@@ -80,6 +85,7 @@ module EE
"error messages: #{kerberos_identity.errors.messages}" "error messages: #{kerberos_identity.errors.messages}"
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Update user email if it changed in LDAP # Update user email if it changed in LDAP
def update_email def update_email
...@@ -110,6 +116,7 @@ module EE ...@@ -110,6 +116,7 @@ module EE
ldap_config.active_directory && (::Gitlab.config.kerberos.enabled || ::AuthHelper.kerberos_enabled? ) ldap_config.active_directory && (::Gitlab.config.kerberos.enabled || ::AuthHelper.kerberos_enabled? )
end end
# rubocop: disable CodeReuse/ActiveRecord
def update_memberships def update_memberships
return if ldap_user.nil? || ldap_user.group_cns.empty? return if ldap_user.nil? || ldap_user.group_cns.empty?
...@@ -119,6 +126,7 @@ module EE ...@@ -119,6 +126,7 @@ module EE
::LdapGroupSyncWorker.perform_async(group_ids, provider) if group_ids.any? ::LdapGroupSyncWorker.perform_async(group_ids, provider) if group_ids.any?
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -6,10 +6,12 @@ module EE ...@@ -6,10 +6,12 @@ module EE
attr_accessor :adapter attr_accessor :adapter
attr_reader :entry attr_reader :entry
# rubocop: disable CodeReuse/ActiveRecord
def self.find_by_cn(cn, adapter) def self.find_by_cn(cn, adapter)
cn = Net::LDAP::Filter.escape(cn) cn = Net::LDAP::Filter.escape(cn)
adapter.group(cn) adapter.group(cn)
end end
# rubocop: enable CodeReuse/ActiveRecord
def initialize(entry, adapter = nil) def initialize(entry, adapter = nil)
Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" } Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
......
...@@ -229,10 +229,12 @@ module EE ...@@ -229,10 +229,12 @@ module EE
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def select_and_preload_group_members(group) def select_and_preload_group_members(group)
group.members.select(:id, :access_level, :user_id, :ldap, :override) group.members.select(:id, :access_level, :user_id, :ldap, :override)
.with_identity_provider(provider).preload(:user) .with_identity_provider(provider).preload(:user)
end end
# rubocop: enable CodeReuse/ActiveRecord
def logger def logger
Rails.logger Rails.logger
......
...@@ -76,12 +76,14 @@ module EE ...@@ -76,12 +76,14 @@ module EE
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def groups_where_group_links_with_provider_ordered def groups_where_group_links_with_provider_ordered
::Group.where_group_links_with_provider(provider) ::Group.where_group_links_with_provider(provider)
.preload(:ldap_group_links) .preload(:ldap_group_links)
.reorder('ldap_sync_last_successful_update_at ASC, namespaces.id ASC') .reorder('ldap_sync_last_successful_update_at ASC, namespaces.id ASC')
.distinct .distinct
end end
# rubocop: enable CodeReuse/ActiveRecord
def config def config
proxy.adapter.config proxy.adapter.config
......
...@@ -108,6 +108,7 @@ module EE ...@@ -108,6 +108,7 @@ module EE
dn dn
end end
# rubocop: disable CodeReuse/ActiveRecord
def member_uid_to_dn(uid) def member_uid_to_dn(uid)
identity = ::Identity.with_secondary_extern_uid(provider, uid).take identity = ::Identity.with_secondary_extern_uid(provider, uid).take
...@@ -126,7 +127,9 @@ module EE ...@@ -126,7 +127,9 @@ module EE
ldap_user.dn ldap_user.dn
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def update_identity(dn, uid) def update_identity(dn, uid)
identity = ::Identity.with_extern_uid(provider, dn).take identity = ::Identity.with_extern_uid(provider, dn).take
...@@ -136,6 +139,7 @@ module EE ...@@ -136,6 +139,7 @@ module EE
identity.secondary_extern_uid = uid identity.secondary_extern_uid = uid
identity.save identity.save
end end
# rubocop: enable CodeReuse/ActiveRecord
def logger def logger
Rails.logger Rails.logger
......
...@@ -15,6 +15,7 @@ module EE ...@@ -15,6 +15,7 @@ module EE
@proxy = proxy @proxy = proxy
end end
# rubocop: disable CodeReuse/ActiveRecord
def update_permissions def update_permissions
dns = member_dns dns = member_dns
return true if dns.empty? return true if dns.empty?
...@@ -40,6 +41,7 @@ module EE ...@@ -40,6 +41,7 @@ module EE
false false
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -7,6 +7,7 @@ module EE ...@@ -7,6 +7,7 @@ module EE
JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN".freeze JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN".freeze
JOB_TOKEN_PARAM = :job_token JOB_TOKEN_PARAM = :job_token
# rubocop: disable CodeReuse/ActiveRecord
def find_user_from_job_token def find_user_from_job_token
return unless route_authentication_setting[:job_token_allowed] return unless route_authentication_setting[:job_token_allowed]
...@@ -20,6 +21,7 @@ module EE ...@@ -20,6 +21,7 @@ module EE
job.user job.user
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -41,9 +41,11 @@ module EE ...@@ -41,9 +41,11 @@ module EE
::Project.update(export_into_project_id, params) ::Project.update(export_into_project_id, params)
end end
# rubocop: disable CodeReuse/ActiveRecord
def export_into_project_exists? def export_into_project_exists?
::Project.exists?(export_into_project_id) ::Project.exists?(export_into_project_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -44,6 +44,7 @@ module EE ...@@ -44,6 +44,7 @@ module EE
usage_data usage_data
end end
# rubocop: disable CodeReuse/ActiveRecord
def projects_mirrored_with_pipelines_enabled def projects_mirrored_with_pipelines_enabled
count(::Project.joins(:project_feature).where( count(::Project.joins(:project_feature).where(
mirror: true, mirror: true,
...@@ -53,7 +54,9 @@ module EE ...@@ -53,7 +54,9 @@ module EE
} }
)) ))
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def service_desk_counts def service_desk_counts
return {} unless ::License.feature_available?(:service_desk) return {} unless ::License.feature_available?(:service_desk)
...@@ -68,7 +71,9 @@ module EE ...@@ -68,7 +71,9 @@ module EE
)) ))
} }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def security_products_usage def security_products_usage
types = { types = {
container_scanning: :container_scanning_jobs, container_scanning: :container_scanning_jobs,
...@@ -81,6 +86,7 @@ module EE ...@@ -81,6 +86,7 @@ module EE
results = count(::Ci::Build.where(name: types.keys).group(:name)) results = count(::Ci::Build.where(name: types.keys).group(:name))
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value } results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value }
end end
# rubocop: enable CodeReuse/ActiveRecord
override :system_usage_data override :system_usage_data
def system_usage_data def system_usage_data
......
...@@ -17,6 +17,7 @@ module EE ...@@ -17,6 +17,7 @@ module EE
# Geo should only update Redis based cache, as data store in the database # Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries. # will be updated on primary and replicated to the secondaries.
# rubocop: disable CodeReuse/ActiveRecord
def perform_geo_secondary(project_id, refresh = []) def perform_geo_secondary(project_id, refresh = [])
project = ::Project.find_by(id: project_id) project = ::Project.find_by(id: project_id)
...@@ -24,6 +25,7 @@ module EE ...@@ -24,6 +25,7 @@ module EE
project.repository.refresh_method_caches(refresh.map(&:to_sym)) project.repository.refresh_method_caches(refresh.map(&:to_sym))
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -18,12 +18,14 @@ module Gitlab ...@@ -18,12 +18,14 @@ module Gitlab
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def identity def identity
@identity ||= current_user.identities.where(provider: :group_saml, @identity ||= current_user.identities.where(provider: :group_saml,
saml_provider: saml_provider, saml_provider: saml_provider,
extern_uid: uid.to_s) extern_uid: uid.to_s)
.first_or_initialize .first_or_initialize
end end
# rubocop: enable CodeReuse/ActiveRecord
def update_group_membership def update_group_membership
MembershipUpdater.new(current_user, saml_provider).execute MembershipUpdater.new(current_user, saml_provider).execute
......
...@@ -8,12 +8,14 @@ module Gitlab ...@@ -8,12 +8,14 @@ module Gitlab
@users = Hash.new(0) @users = Hash.new(0)
end end
# rubocop: disable CodeReuse/ActiveRecord
def calculate(number_of_approvers) def calculate(number_of_approvers)
involved_users involved_users
# Picks most active users from hash like: {user1: 2, user2: 6} # Picks most active users from hash like: {user1: 2, user2: 6}
@users.sort_by { |user, count| -count }.map(&:first).take(number_of_approvers) @users.sort_by { |user, count| -count }.map(&:first).take(number_of_approvers)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
if blob.project.feature_available?(:code_owners) if blob.project.feature_available?(:code_owners)
Loader.new(blob.project, blob.commit_id, blob.path).users Loader.new(blob.project, blob.commit_id, blob.path).users
else else
User.none User.none # rubocop: disable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
end end
def users def users
return User.none if code_owners_file.empty? return User.none if code_owners_file.empty? # rubocop: disable CodeReuse/ActiveRecord
owners = code_owners_file.owners_for_path(@path) owners = code_owners_file.owners_for_path(@path)
extracted_users = Gitlab::UserExtractor.new(owners).users extracted_users = Gitlab::UserExtractor.new(owners).users
......
module Gitlab module Gitlab
module Elastic module Elastic
class Helper class Helper
# rubocop: disable CodeReuse/ActiveRecord
def self.create_empty_index def self.create_empty_index
index_name = Project.index_name index_name = Project.index_name
settings = {} settings = {}
...@@ -32,6 +33,7 @@ module Gitlab ...@@ -32,6 +33,7 @@ module Gitlab
mappings: mappings.to_hash mappings: mappings.to_hash
} }
end end
# rubocop: enable CodeReuse/ActiveRecord
def self.delete_index def self.delete_index
Project.__elasticsearch__.delete_index! Project.__elasticsearch__.delete_index!
......
...@@ -66,6 +66,7 @@ module Gitlab ...@@ -66,6 +66,7 @@ module Gitlab
raise Error, output unless status&.zero? raise Error, output unless status&.zero?
end end
# rubocop: disable CodeReuse/ActiveRecord
def update_index_status(to_sha) def update_index_status(to_sha)
head_commit = repository.try(:commit) head_commit = repository.try(:commit)
...@@ -88,6 +89,7 @@ module Gitlab ...@@ -88,6 +89,7 @@ module Gitlab
index_status.update(last_commit: sha, indexed_at: Time.now) index_status.update(last_commit: sha, indexed_at: Time.now)
project.index_status(true) project.index_status(true)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -248,6 +248,7 @@ module Gitlab ...@@ -248,6 +248,7 @@ module Gitlab
} }
end end
# rubocop: disable CodeReuse/ActiveRecord
def guest_project_ids def guest_project_ids
if current_user if current_user
current_user.authorized_projects current_user.authorized_projects
...@@ -257,6 +258,7 @@ module Gitlab ...@@ -257,6 +258,7 @@ module Gitlab
[] []
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def non_guest_project_ids def non_guest_project_ids
if limit_project_ids == :any if limit_project_ids == :any
......
...@@ -30,6 +30,7 @@ module Gitlab ...@@ -30,6 +30,7 @@ module Gitlab
mail_key mail_key
end end
# rubocop: disable CodeReuse/ActiveRecord
def project def project
return @project if instance_variable_defined?(:@project) return @project if instance_variable_defined?(:@project)
...@@ -39,6 +40,7 @@ module Gitlab ...@@ -39,6 +40,7 @@ module Gitlab
@project = found_project&.service_desk_enabled? ? found_project : nil @project = found_project&.service_desk_enabled? ? found_project : nil
end end
# rubocop: enable CodeReuse/ActiveRecord
def create_issue! def create_issue!
# NB: the support bot is specifically forbidden # NB: the support bot is specifically forbidden
......
...@@ -18,13 +18,17 @@ module Gitlab ...@@ -18,13 +18,17 @@ module Gitlab
self.cache_value(:geo_node_current) { GeoNode.current_node } self.cache_value(:geo_node_current) { GeoNode.current_node }
end end
# rubocop: disable CodeReuse/ActiveRecord
def self.primary_node def self.primary_node
self.cache_value(:geo_primary_node) { GeoNode.find_by(primary: true) } self.cache_value(:geo_primary_node) { GeoNode.find_by(primary: true) }
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def self.secondary_nodes def self.secondary_nodes
self.cache_value(:geo_secondary_nodes) { GeoNode.where(primary: false) } self.cache_value(:geo_secondary_nodes) { GeoNode.where(primary: false) }
end end
# rubocop: enable CodeReuse/ActiveRecord
def self.connected? def self.connected?
Gitlab::Database.postgresql? && GeoNode.connected? && GeoNode.table_exists? Gitlab::Database.postgresql? && GeoNode.connected? && GeoNode.table_exists?
......
...@@ -46,6 +46,7 @@ module Gitlab ...@@ -46,6 +46,7 @@ module Gitlab
end end
# accepts a block that should return whether the event was handled # accepts a block that should return whether the event was handled
# rubocop: disable CodeReuse/ActiveRecord
def fill_gaps def fill_gaps
with_redis do |redis| with_redis do |redis|
redis.zremrangebyscore(GEO_EVENT_LOG_GAPS, '-inf', outdated_timestamp) redis.zremrangebyscore(GEO_EVENT_LOG_GAPS, '-inf', outdated_timestamp)
...@@ -59,6 +60,7 @@ module Gitlab ...@@ -59,6 +60,7 @@ module Gitlab
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -19,6 +19,7 @@ module Gitlab ...@@ -19,6 +19,7 @@ module Gitlab
# #
# Subclasses should return the number of bytes downloaded, # Subclasses should return the number of bytes downloaded,
# or nil or -1 if a failure occurred. # or nil or -1 if a failure occurred.
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
upload = Upload.find_by(id: object_db_id) upload = Upload.find_by(id: object_db_id)
return fail_before_transfer unless upload.present? return fail_before_transfer unless upload.present?
...@@ -26,6 +27,7 @@ module Gitlab ...@@ -26,6 +27,7 @@ module Gitlab
transfer = ::Gitlab::Geo::FileTransfer.new(object_type.to_sym, upload) transfer = ::Gitlab::Geo::FileTransfer.new(object_type.to_sym, upload)
Result.from_transfer_result(transfer.download_from_primary) Result.from_transfer_result(transfer.download_from_primary)
end end
# rubocop: enable CodeReuse/ActiveRecord
class Result class Result
attr_reader :success, :bytes_downloaded, :primary_missing_file, :failed_before_transfer attr_reader :success, :bytes_downloaded, :primary_missing_file, :failed_before_transfer
......
...@@ -18,6 +18,7 @@ module Gitlab ...@@ -18,6 +18,7 @@ module Gitlab
@message = message @message = message
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
recorded_file = Upload.find_by(id: object_db_id) recorded_file = Upload.find_by(id: object_db_id)
...@@ -27,6 +28,7 @@ module Gitlab ...@@ -27,6 +28,7 @@ module Gitlab
success(CarrierWave::SanitizedFile.new(recorded_file.absolute_path)) success(CarrierWave::SanitizedFile.new(recorded_file.absolute_path))
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -7,6 +7,7 @@ module Gitlab ...@@ -7,6 +7,7 @@ module Gitlab
# #
# TODO: Rearrange things so this class does not inherit FileDownloader # TODO: Rearrange things so this class does not inherit FileDownloader
class JobArtifactDownloader < FileDownloader class JobArtifactDownloader < FileDownloader
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id) job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
return fail_before_transfer unless job_artifact.present? return fail_before_transfer unless job_artifact.present?
...@@ -14,6 +15,7 @@ module Gitlab ...@@ -14,6 +15,7 @@ module Gitlab
transfer = ::Gitlab::Geo::JobArtifactTransfer.new(job_artifact) transfer = ::Gitlab::Geo::JobArtifactTransfer.new(job_artifact)
Result.from_transfer_result(transfer.download_from_primary) Result.from_transfer_result(transfer.download_from_primary)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -6,6 +6,7 @@ module Gitlab ...@@ -6,6 +6,7 @@ module Gitlab
# #
# TODO: Rearrange things so this class does not inherit from FileUploader # TODO: Rearrange things so this class does not inherit from FileUploader
class JobArtifactUploader < ::Gitlab::Geo::FileUploader class JobArtifactUploader < ::Gitlab::Geo::FileUploader
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id) job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
...@@ -21,6 +22,7 @@ module Gitlab ...@@ -21,6 +22,7 @@ module Gitlab
success(job_artifact.file) success(job_artifact.file)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -63,12 +63,14 @@ module Gitlab ...@@ -63,12 +63,14 @@ module Gitlab
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def hmac_secret(access_key) def hmac_secret(access_key)
@hmac_secret ||= begin @hmac_secret ||= begin
geo_node = GeoNode.find_by(access_key: access_key, enabled: true) geo_node = GeoNode.find_by(access_key: access_key, enabled: true)
geo_node&.secret_access_key geo_node&.secret_access_key
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def decode_auth_header def decode_auth_header
return unless auth_header.present? return unless auth_header.present?
......
...@@ -7,6 +7,7 @@ module Gitlab ...@@ -7,6 +7,7 @@ module Gitlab
# #
# TODO: Rearrange things so this class does not inherit FileDownloader # TODO: Rearrange things so this class does not inherit FileDownloader
class LfsDownloader < FileDownloader class LfsDownloader < FileDownloader
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
lfs_object = LfsObject.find_by(id: object_db_id) lfs_object = LfsObject.find_by(id: object_db_id)
return fail_before_transfer unless lfs_object.present? return fail_before_transfer unless lfs_object.present?
...@@ -14,6 +15,7 @@ module Gitlab ...@@ -14,6 +15,7 @@ module Gitlab
transfer = ::Gitlab::Geo::LfsTransfer.new(lfs_object) transfer = ::Gitlab::Geo::LfsTransfer.new(lfs_object)
Result.from_transfer_result(transfer.download_from_primary) Result.from_transfer_result(transfer.download_from_primary)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -6,6 +6,7 @@ module Gitlab ...@@ -6,6 +6,7 @@ module Gitlab
# #
# TODO: Rearrange things so this class does not inherit from FileUploader # TODO: Rearrange things so this class does not inherit from FileUploader
class LfsUploader < FileUploader class LfsUploader < FileUploader
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
lfs_object = LfsObject.find_by(id: object_db_id) lfs_object = LfsObject.find_by(id: object_db_id)
...@@ -20,6 +21,7 @@ module Gitlab ...@@ -20,6 +21,7 @@ module Gitlab
success(lfs_object.file) success(lfs_object.file)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -104,6 +104,7 @@ module Gitlab ...@@ -104,6 +104,7 @@ module Gitlab
@exit @exit
end end
# rubocop: disable CodeReuse/ActiveRecord
def can_replay?(event_log) def can_replay?(event_log)
return true if event_log.project_id.nil? return true if event_log.project_id.nil?
...@@ -112,6 +113,7 @@ module Gitlab ...@@ -112,6 +113,7 @@ module Gitlab
Gitlab::Geo.current_node&.projects_include?(event_log.project_id) Gitlab::Geo.current_node&.projects_include?(event_log.project_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# Sleeps for the expired TTL that remains on the lease plus some random seconds. # Sleeps for the expired TTL that remains on the lease plus some random seconds.
# #
......
...@@ -6,6 +6,7 @@ module Gitlab ...@@ -6,6 +6,7 @@ module Gitlab
BATCH_SIZE = 50 BATCH_SIZE = 50
# fetches up to BATCH_SIZE next events and keep track of batches # fetches up to BATCH_SIZE next events and keep track of batches
# rubocop: disable CodeReuse/ActiveRecord
def fetch_in_batches(batch_size: BATCH_SIZE) def fetch_in_batches(batch_size: BATCH_SIZE)
last_id = last_processed_id last_id = last_processed_id
...@@ -18,6 +19,7 @@ module Gitlab ...@@ -18,6 +19,7 @@ module Gitlab
break unless Lease.renew! break unless Lease.renew!
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -15,9 +15,11 @@ module Gitlab ...@@ -15,9 +15,11 @@ module Gitlab
attr_reader :event, :created_at, :logger attr_reader :event, :created_at, :logger
# rubocop: disable CodeReuse/ActiveRecord
def registry def registry
@registry ||= ::Geo::ProjectRegistry.find_or_initialize_by(project_id: event.project_id) @registry ||= ::Geo::ProjectRegistry.find_or_initialize_by(project_id: event.project_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def skippable? def skippable?
registry.new_record? registry.new_record?
......
...@@ -19,9 +19,11 @@ module Gitlab ...@@ -19,9 +19,11 @@ module Gitlab
private private
# rubocop: disable CodeReuse/ActiveRecord
def file_registry_job_artifacts def file_registry_job_artifacts
@file_registry_job_artifacts ||= ::Geo::JobArtifactRegistry.where(artifact_id: event.job_artifact_id) @file_registry_job_artifacts ||= ::Geo::JobArtifactRegistry.where(artifact_id: event.job_artifact_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def file_path def file_path
@file_path ||= File.join(::JobArtifactUploader.root, event.file_path) @file_path ||= File.join(::JobArtifactUploader.root, event.file_path)
......
...@@ -5,12 +5,14 @@ module Gitlab ...@@ -5,12 +5,14 @@ module Gitlab
class LfsObjectDeletedEvent class LfsObjectDeletedEvent
include BaseEvent include BaseEvent
# rubocop: disable CodeReuse/ActiveRecord
def process def process
# Must always schedule, regardless of shard health # Must always schedule, regardless of shard health
job_id = ::Geo::FileRemovalWorker.perform_async(file_path) job_id = ::Geo::FileRemovalWorker.perform_async(file_path)
log_event(job_id) log_event(job_id)
::Geo::FileRegistry.lfs_objects.where(file_id: event.lfs_object_id).delete_all ::Geo::FileRegistry.lfs_objects.where(file_id: event.lfs_object_id).delete_all
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -28,9 +28,11 @@ module Gitlab ...@@ -28,9 +28,11 @@ module Gitlab
).async_execute ).async_execute
end end
# rubocop: disable CodeReuse/ActiveRecord
def delete_project_registry_entries def delete_project_registry_entries
::Geo::ProjectRegistry.where(project_id: event.project_id).delete_all ::Geo::ProjectRegistry.where(project_id: event.project_id).delete_all
end end
# rubocop: enable CodeReuse/ActiveRecord
def log_event(job_id) def log_event(job_id)
logger.event_info( logger.event_info(
......
...@@ -5,10 +5,12 @@ module Gitlab ...@@ -5,10 +5,12 @@ module Gitlab
class UploadDeletedEvent class UploadDeletedEvent
include BaseEvent include BaseEvent
# rubocop: disable CodeReuse/ActiveRecord
def process def process
log_event log_event
::Geo::FileRegistry.where(file_id: event.upload_id, file_type: event.upload_type).delete_all ::Geo::FileRegistry.where(file_id: event.upload_id, file_type: event.upload_type).delete_all
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -13,6 +13,7 @@ module Gitlab ...@@ -13,6 +13,7 @@ module Gitlab
# #
# Returns an Array containing all the Groups, including their preloaded # Returns an Array containing all the Groups, including their preloaded
# plans. # plans.
# rubocop: disable CodeReuse/ActiveRecord
def preload(groups) def preload(groups)
groups_and_ancestors = groups_and_ancestors_for(groups) groups_and_ancestors = groups_and_ancestors_for(groups)
...@@ -52,6 +53,7 @@ module Gitlab ...@@ -52,6 +53,7 @@ module Gitlab
group.memoized_plans = plans_map[group.id].map { |id| plans[id] } group.memoized_plans = plans_map[group.id].map { |id| plans[id] }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Returns an ActiveRecord::Relation that includes the given groups, and all # Returns an ActiveRecord::Relation that includes the given groups, and all
# their (recursive) ancestors. # their (recursive) ancestors.
......
...@@ -43,10 +43,12 @@ module Gitlab ...@@ -43,10 +43,12 @@ module Gitlab
private private
# rubocop: disable CodeReuse/ActiveRecord
def find_by_login(login) def find_by_login(login)
identity = ::Identity.with_extern_uid(:kerberos, login).take identity = ::Identity.with_extern_uid(:kerberos, login).take
identity && identity.user identity && identity.user
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -49,6 +49,7 @@ class Gitlab::PathLocksFinder ...@@ -49,6 +49,7 @@ class Gitlab::PathLocksFinder
tokens tokens
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_by_token(token) def find_by_token(token)
if @non_locked_paths.include?(token) if @non_locked_paths.include?(token)
return false return false
...@@ -62,8 +63,11 @@ class Gitlab::PathLocksFinder ...@@ -62,8 +63,11 @@ class Gitlab::PathLocksFinder
lock lock
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_downstream(path) def find_downstream(path)
@project.path_locks.find_by("path LIKE ?", "#{sanitize_sql_like(path)}%") @project.path_locks.find_by("path LIKE ?", "#{sanitize_sql_like(path)}%")
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
module SlashCommands module SlashCommands
module Presenters module Presenters
class Run < Presenters::Base class Run < Presenters::Base
# rubocop: disable CodeReuse/ActiveRecord
def present(pipeline) def present(pipeline)
build = pipeline.builds.take build = pipeline.builds.take
...@@ -13,6 +14,7 @@ module Gitlab ...@@ -13,6 +14,7 @@ module Gitlab
unsupported_chat_service unsupported_chat_service
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def unsupported_chat_service def unsupported_chat_service
ephemeral_response(text: 'Sorry, this chat service is currently not supported by GitLab ChatOps.') ephemeral_response(text: 'Sorry, this chat service is currently not supported by GitLab ChatOps.')
......
...@@ -171,6 +171,7 @@ module API ...@@ -171,6 +171,7 @@ module API
optional(*optional_attributes) optional(*optional_attributes)
at_least_one_of(*optional_attributes) at_least_one_of(*optional_attributes)
end end
# rubocop: disable CodeReuse/ActiveRecord
put "application/settings" do put "application/settings" do
attrs = declared_params(include_missing: false) attrs = declared_params(include_missing: false)
...@@ -216,5 +217,6 @@ module API ...@@ -216,5 +217,6 @@ module API
render_validation_error!(current_settings) render_validation_error!(current_settings)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -266,6 +266,7 @@ module Gitlab ...@@ -266,6 +266,7 @@ module Gitlab
check_change_access! check_change_access!
end end
# rubocop: disable CodeReuse/ActiveRecord
def check_change_access! def check_change_access!
# If there are worktrees with a HEAD pointing to a non-existent object, # If there are worktrees with a HEAD pointing to a non-existent object,
# calls to `git rev-list --all` will fail in git 2.15+. This should also # calls to `git rev-list --all` will fail in git 2.15+. This should also
...@@ -291,6 +292,7 @@ module Gitlab ...@@ -291,6 +292,7 @@ module Gitlab
raise UnauthorizedError, Gitlab::RepositorySizeError.new(project).new_changes_error raise UnauthorizedError, Gitlab::RepositorySizeError.new(project).new_changes_error
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def check_single_change_access(change, skip_lfs_integrity_check: false) def check_single_change_access(change, skip_lfs_integrity_check: false)
Checks::ChangeAccess.new( Checks::ChangeAccess.new(
......
...@@ -37,9 +37,11 @@ module Gitlab ...@@ -37,9 +37,11 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def roots def roots
base_and_ancestors.where(namespaces: { parent_id: nil }) base_and_ancestors.where(namespaces: { parent_id: nil })
end end
# rubocop: enable CodeReuse/ActiveRecord
# Returns a relation that includes the ancestors_base set of groups # Returns a relation that includes the ancestors_base set of groups
# and all their ancestors (recursively). # and all their ancestors (recursively).
......
...@@ -314,13 +314,16 @@ if $0 == __FILE__ ...@@ -314,13 +314,16 @@ if $0 == __FILE__
end end
describe '.run_git_command' do describe '.run_git_command' do
# rubocop: disable CodeReuse/ActiveRecord
it 'returns the single output when there is a single command' do it 'returns the single output when there is a single command' do
output = run_git_command('status') output = run_git_command('status')
expect(output).to be_kind_of(String) expect(output).to be_kind_of(String)
expect(self).to have_received(:warn).with(/git status/) expect(self).to have_received(:warn).with(/git status/)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
it 'returns an array of output for more commands' do it 'returns an array of output for more commands' do
output = run_git_command('status', 'help') output = run_git_command('status', 'help')
...@@ -328,6 +331,7 @@ if $0 == __FILE__ ...@@ -328,6 +331,7 @@ if $0 == __FILE__
expect(self).to have_received(:warn).with(/git status/) expect(self).to have_received(:warn).with(/git status/)
expect(self).to have_received(:warn).with(/git help/) expect(self).to have_received(:warn).with(/git help/)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
describe '.matching_ce_refs' do describe '.matching_ce_refs' do
......
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