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