Commit 0430b764 authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Rémy Coutable

Enable Style/DotPosition Rubocop 👮

parent 78ee24ba
...@@ -164,6 +164,11 @@ Style/DefWithParentheses: ...@@ -164,6 +164,11 @@ Style/DefWithParentheses:
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false
# Multi-line method chaining should be done with leading dots.
Style/DotPosition:
Enabled: true
EnforcedStyle: leading
# This cop checks for uses of double negation (!!) to convert something # This cop checks for uses of double negation (!!) to convert something
# to a boolean value. As this is both cryptic and usually redundant, it # to a boolean value. As this is both cryptic and usually redundant, it
# should be avoided. # should be avoided.
......
...@@ -88,13 +88,6 @@ Security/YAMLLoad: ...@@ -88,13 +88,6 @@ Security/YAMLLoad:
Style/BarePercentLiterals: Style/BarePercentLiterals:
Enabled: false Enabled: false
# Offense count: 1403
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: leading, trailing
Style/DotPosition:
Enabled: false
# Offense count: 5 # Offense count: 5
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/EachWithObject: Style/EachWithObject:
......
...@@ -97,8 +97,8 @@ module CreatesCommit ...@@ -97,8 +97,8 @@ module CreatesCommit
def merge_request_exists? def merge_request_exists?
return @merge_request if defined?(@merge_request) return @merge_request if defined?(@merge_request)
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened. @merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
find_by(source_project_id: @project_to_commit_into, source_branch: @branch_name, target_branch: @start_branch) .find_by(source_project_id: @project_to_commit_into, source_branch: @branch_name, target_branch: @start_branch)
end end
def different_project? def different_project?
......
...@@ -15,8 +15,8 @@ module MembershipActions ...@@ -15,8 +15,8 @@ module MembershipActions
end end
def destroy def destroy
Members::DestroyService.new(membershipable, current_user, params). Members::DestroyService.new(membershipable, current_user, params)
execute(:all) .execute(:all)
respond_to do |format| respond_to do |format|
format.html do format.html do
...@@ -42,8 +42,8 @@ module MembershipActions ...@@ -42,8 +42,8 @@ module MembershipActions
end end
def leave def leave
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id). member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id)
execute(:all) .execute(:all)
notice = notice =
if member.request? if member.request?
......
...@@ -22,8 +22,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -22,8 +22,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end end
def starred def starred
@projects = load_projects(params.merge(starred: true)). @projects = load_projects(params.merge(starred: true))
includes(:forked_from_project, :tags).page(params[:page]) .includes(:forked_from_project, :tags).page(params[:page])
@groups = [] @groups = []
...@@ -45,8 +45,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -45,8 +45,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end end
def load_projects(finder_params) def load_projects(finder_params)
ProjectsFinder.new(params: finder_params, current_user: current_user). ProjectsFinder.new(params: finder_params, current_user: current_user)
execute.includes(:route, namespace: :route) .execute.includes(:route, namespace: :route)
end end
def load_events def load_events
......
...@@ -49,7 +49,7 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -49,7 +49,7 @@ class Explore::ProjectsController < Explore::ApplicationController
private private
def load_projects def load_projects
ProjectsFinder.new(current_user: current_user, params: params). ProjectsFinder.new(current_user: current_user, params: params)
execute.includes(:route, namespace: :route) .execute.includes(:route, namespace: :route)
end end
end end
...@@ -11,8 +11,8 @@ class JwtController < ApplicationController ...@@ -11,8 +11,8 @@ class JwtController < ApplicationController
service = SERVICES[params[:service]] service = SERVICES[params[:service]]
return head :not_found unless service return head :not_found unless service
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params). result = service.new(@authentication_result.project, @authentication_result.actor, auth_params)
execute(authentication_abilities: @authentication_result.authentication_abilities) .execute(authentication_abilities: @authentication_result.authentication_abilities)
render json: result, status: result[:http_status] render json: result, status: result[:http_status]
end end
......
...@@ -144,7 +144,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController ...@@ -144,7 +144,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
end end
def log_audit_event(user, options = {}) def log_audit_event(user, options = {})
AuditEventService.new(user, user, options). AuditEventService.new(user, user, options)
for_authentication.security_event .for_authentication.security_event
end end
end end
...@@ -49,9 +49,9 @@ class ProfilesController < Profiles::ApplicationController ...@@ -49,9 +49,9 @@ class ProfilesController < Profiles::ApplicationController
end end
def audit_log def audit_log
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id). @events = AuditEvent.where(entity_type: "User", entity_id: current_user.id)
order("created_at DESC"). .order("created_at DESC")
page(params[:page]) .page(params[:page])
end end
def update_username def update_username
......
...@@ -187,7 +187,7 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -187,7 +187,7 @@ class Projects::BlobController < Projects::ApplicationController
end end
def set_last_commit_sha def set_last_commit_sha
@last_commit_sha = Gitlab::Git::Commit. @last_commit_sha = Gitlab::Git::Commit
last_for_path(@repository, @ref, @path).sha .last_for_path(@repository, @ref, @path).sha
end end
end end
...@@ -37,8 +37,8 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -37,8 +37,8 @@ class Projects::BranchesController < Projects::ApplicationController
redirect_to_autodeploy = project.empty_repo? && project.deployment_services.present? redirect_to_autodeploy = project.empty_repo? && project.deployment_services.present?
result = CreateBranchService.new(project, current_user). result = CreateBranchService.new(project, current_user)
execute(branch_name, ref) .execute(branch_name, ref)
if params[:issue_iid] if params[:issue_iid]
issue = IssuesFinder.new(current_user, project_id: @project.id).find_by(iid: params[:issue_iid]) issue = IssuesFinder.new(current_user, project_id: @project.id).find_by(iid: params[:issue_iid])
......
...@@ -18,11 +18,11 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -18,11 +18,11 @@ class Projects::CommitsController < Projects::ApplicationController
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset) @repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end end
@note_counts = project.notes.where(commit_id: @commits.map(&:id)). @note_counts = project.notes.where(commit_id: @commits.map(&:id))
group(:commit_id).count .group(:commit_id).count
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened. @merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref) .find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
respond_to do |format| respond_to do |format|
format.html format.html
......
...@@ -61,7 +61,7 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -61,7 +61,7 @@ class Projects::CompareController < Projects::ApplicationController
end end
def merge_request def merge_request
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened. @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref) .find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
end end
end end
...@@ -143,8 +143,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -143,8 +143,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
# Get commits from repository # Get commits from repository
# or from cache if already merged # or from cache if already merged
@commits = @merge_request.commits @commits = @merge_request.commits
@note_counts = Note.where(commit_id: @commits.map(&:id)). @note_counts = Note.where(commit_id: @commits.map(&:id))
group(:commit_id).count .group(:commit_id).count
render json: { html: view_to_html_string('projects/merge_requests/show/_commits') } render json: { html: view_to_html_string('projects/merge_requests/show/_commits') }
end end
...@@ -192,9 +192,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -192,9 +192,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
begin begin
MergeRequests::Conflicts::ResolveService. MergeRequests::Conflicts::ResolveService
new(merge_request). .new(merge_request)
execute(current_user, params) .execute(current_user, params)
flash[:notice] = 'All merge conflicts were resolved. The merge request can now be merged.' flash[:notice] = 'All merge conflicts were resolved. The merge request can now be merged.'
...@@ -562,8 +562,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -562,8 +562,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@commits = @merge_request.compare_commits.reverse @commits = @merge_request.compare_commits.reverse
@commit = @merge_request.diff_head_commit @commit = @merge_request.diff_head_commit
@note_counts = Note.where(commit_id: @commits.map(&:id)). @note_counts = Note.where(commit_id: @commits.map(&:id))
group(:commit_id).count .group(:commit_id).count
@labels = LabelsFinder.new(current_user, project_id: @project.id).execute @labels = LabelsFinder.new(current_user, project_id: @project.id).execute
......
...@@ -14,8 +14,8 @@ module Projects ...@@ -14,8 +14,8 @@ module Projects
def define_runners_variables def define_runners_variables
@project_runners = @project.runners.ordered @project_runners = @project.runners.ordered
@assignable_runners = current_user.ci_authorized_runners. @assignable_runners = current_user.ci_authorized_runners
assignable_for(project).ordered.page(params[:page]).per(20) .assignable_for(project).ordered.page(params[:page]).per(20)
@shared_runners = Ci::Runner.shared.active @shared_runners = Ci::Runner.shared.active
@shared_runners_count = @shared_runners.count(:all) @shared_runners_count = @shared_runners.count(:all)
end end
......
...@@ -29,8 +29,8 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -29,8 +29,8 @@ class Projects::TagsController < Projects::ApplicationController
end end
def create def create
result = Tags::CreateService.new(@project, current_user). result = Tags::CreateService.new(@project, current_user)
execute(params[:tag_name], params[:ref], params[:message], params[:release_description]) .execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
if result[:status] == :success if result[:status] == :success
@tag = result[:tag] @tag = result[:tag]
......
...@@ -128,8 +128,8 @@ class SessionsController < Devise::SessionsController ...@@ -128,8 +128,8 @@ class SessionsController < Devise::SessionsController
end end
def log_audit_event(user, options = {}) def log_audit_event(user, options = {})
AuditEventService.new(user, user, options). AuditEventService.new(user, user, options)
for_authentication.security_event .for_authentication.security_event
end end
def log_user_activity(user) def log_user_activity(user)
......
...@@ -4,8 +4,8 @@ module Sherlock ...@@ -4,8 +4,8 @@ module Sherlock
def find_transaction def find_transaction
if params[:transaction_id] if params[:transaction_id]
@transaction = Gitlab::Sherlock.collection. @transaction = Gitlab::Sherlock.collection
find_transaction(params[:transaction_id]) .find_transaction(params[:transaction_id])
end end
end end
end end
......
...@@ -106,11 +106,11 @@ class UsersController < ApplicationController ...@@ -106,11 +106,11 @@ class UsersController < ApplicationController
def load_events def load_events
# Get user activity feed for projects common for both users # Get user activity feed for projects common for both users
@events = user.recent_events. @events = user.recent_events
merge(projects_for_current_user). .merge(projects_for_current_user)
references(:project). .references(:project)
with_associations. .with_associations
limit_recent(20, params[:offset]) .limit_recent(20, params[:offset])
end end
def load_projects def load_projects
......
...@@ -33,8 +33,8 @@ class EventsFinder ...@@ -33,8 +33,8 @@ class EventsFinder
private private
def by_current_user_access(events) def by_current_user_access(events)
events.merge(ProjectsFinder.new(current_user: current_user).execute). events.merge(ProjectsFinder.new(current_user: current_user).execute)
joins(:project) .joins(:project)
end end
def by_action(events) def by_action(events)
......
...@@ -8,9 +8,9 @@ class GroupMembersFinder ...@@ -8,9 +8,9 @@ class GroupMembersFinder
return group_members unless @group.parent return group_members unless @group.parent
parents_members = GroupMember.non_request. parents_members = GroupMember.non_request
where(source_id: @group.ancestors.select(:id)). .where(source_id: @group.ancestors.select(:id))
where.not(user_id: @group.users.select(:id)) .where.not(user_id: @group.users.select(:id))
wheres = ["members.id IN (#{group_members.select(:id).to_sql})"] wheres = ["members.id IN (#{group_members.select(:id).to_sql})"]
wheres << "members.id IN (#{parents_members.select(:id).to_sql})" wheres << "members.id IN (#{parents_members.select(:id).to_sql})"
......
...@@ -8,10 +8,10 @@ module FormHelper ...@@ -8,10 +8,10 @@ module FormHelper
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
content_tag(:h4, headline) << content_tag(:h4, headline) <<
content_tag(:ul) do content_tag(:ul) do
model.errors.full_messages. model.errors.full_messages
map { |msg| content_tag(:li, msg) }. .map { |msg| content_tag(:li, msg) }
join. .join
html_safe .html_safe
end end
end end
end end
......
...@@ -194,8 +194,8 @@ module ProjectsHelper ...@@ -194,8 +194,8 @@ module ProjectsHelper
end end
def load_pipeline_status(projects) def load_pipeline_status(projects)
Gitlab::Cache::Ci::ProjectPipelineStatus. Gitlab::Cache::Ci::ProjectPipelineStatus
load_in_batch_for_projects(projects) .load_in_batch_for_projects(projects)
end end
private private
......
...@@ -97,8 +97,8 @@ module SearchHelper ...@@ -97,8 +97,8 @@ module SearchHelper
# Autocomplete results for the current user's projects # Autocomplete results for the current user's projects
def projects_autocomplete(term, limit = 5) def projects_autocomplete(term, limit = 5)
current_user.authorized_projects.search_by_title(term). current_user.authorized_projects.search_by_title(term)
sorted_by_stars.non_archived.limit(limit).map do |p| .sorted_by_stars.non_archived.limit(limit).map do |p|
{ {
category: "Projects", category: "Projects",
id: p.id, id: p.id,
......
...@@ -6,8 +6,8 @@ module WikiHelper ...@@ -6,8 +6,8 @@ module WikiHelper
# Returns a String composed of the capitalized name of each directory and the # Returns a String composed of the capitalized name of each directory and the
# capitalized name of the page itself. # capitalized name of the page itself.
def breadcrumb(page_slug) def breadcrumb(page_slug)
page_slug.split('/'). page_slug.split('/')
map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }. .map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }
join(' / ') .join(' / ')
end end
end end
...@@ -19,9 +19,9 @@ class AwardEmoji < ActiveRecord::Base ...@@ -19,9 +19,9 @@ class AwardEmoji < ActiveRecord::Base
class << self class << self
def votes_for_collection(ids, type) def votes_for_collection(ids, type)
select('name', 'awardable_id', 'COUNT(*) as count'). select('name', 'awardable_id', 'COUNT(*) as count')
where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids). .where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids)
group('name', 'awardable_id') .group('name', 'awardable_id')
end end
end end
......
...@@ -168,8 +168,8 @@ module Ci ...@@ -168,8 +168,8 @@ module Ci
end end
def stages_names def stages_names
statuses.order(:stage_idx).distinct. statuses.order(:stage_idx).distinct
pluck(:stage, :stage_idx).map(&:first) .pluck(:stage, :stage_idx).map(&:first)
end end
def legacy_stage(name) def legacy_stage(name)
......
...@@ -30,8 +30,8 @@ module Ci ...@@ -30,8 +30,8 @@ module Ci
scope :assignable_for, ->(project) do scope :assignable_for, ->(project) do
# FIXME: That `to_sql` is needed to workaround a weird Rails bug. # FIXME: That `to_sql` is needed to workaround a weird Rails bug.
# Without that, placeholders would miss one and couldn't match. # Without that, placeholders would miss one and couldn't match.
where(locked: false). where(locked: false)
where.not("id IN (#{project.runners.select(:id).to_sql})").specific .where.not("id IN (#{project.runners.select(:id).to_sql})").specific
end end
validate :tag_constraints validate :tag_constraints
......
...@@ -161,9 +161,9 @@ module Issuable ...@@ -161,9 +161,9 @@ module Issuable
# #
milestones_due_date = 'MIN(milestones.due_date)' milestones_due_date = 'MIN(milestones.due_date)'
order_milestone_due_asc. order_milestone_due_asc
order_labels_priority(excluded_labels: excluded_labels, extra_select_columns: [milestones_due_date]). .order_labels_priority(excluded_labels: excluded_labels, extra_select_columns: [milestones_due_date])
reorder(Gitlab::Database.nulls_last_order(milestones_due_date, 'ASC'), .reorder(Gitlab::Database.nulls_last_order(milestones_due_date, 'ASC'),
Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
end end
...@@ -182,9 +182,9 @@ module Issuable ...@@ -182,9 +182,9 @@ module Issuable
"(#{highest_priority}) AS highest_priority" "(#{highest_priority}) AS highest_priority"
] + extra_select_columns ] + extra_select_columns
select(select_columns.join(', ')). select(select_columns.join(', '))
group(arel_table[:id]). .group(arel_table[:id])
reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) .reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
end end
def with_label(title, sort = nil) def with_label(title, sort = nil)
......
...@@ -18,10 +18,10 @@ module RelativePositioning ...@@ -18,10 +18,10 @@ module RelativePositioning
prev_pos = nil prev_pos = nil
if self.relative_position if self.relative_position
prev_pos = self.class. prev_pos = self.class
in_projects(project.id). .in_projects(project.id)
where('relative_position < ?', self.relative_position). .where('relative_position < ?', self.relative_position)
maximum(:relative_position) .maximum(:relative_position)
end end
prev_pos prev_pos
...@@ -31,10 +31,10 @@ module RelativePositioning ...@@ -31,10 +31,10 @@ module RelativePositioning
next_pos = nil next_pos = nil
if self.relative_position if self.relative_position
next_pos = self.class. next_pos = self.class
in_projects(project.id). .in_projects(project.id)
where('relative_position > ?', self.relative_position). .where('relative_position > ?', self.relative_position)
minimum(:relative_position) .minimum(:relative_position)
end end
next_pos next_pos
......
...@@ -39,12 +39,12 @@ module Sortable ...@@ -39,12 +39,12 @@ module Sortable
private private
def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: []) def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: [])
query = Label.select(LabelPriority.arel_table[:priority].minimum). query = Label.select(LabelPriority.arel_table[:priority].minimum)
left_join_priorities. .left_join_priorities
joins(:label_links). .joins(:label_links)
where("label_priorities.project_id = #{project_column}"). .where("label_priorities.project_id = #{project_column}")
where("label_links.target_id = #{target_column}"). .where("label_links.target_id = #{target_column}")
reorder(nil) .reorder(nil)
query = query =
if target_type_column if target_type_column
......
...@@ -27,16 +27,16 @@ module Subscribable ...@@ -27,16 +27,16 @@ module Subscribable
end end
def subscribers(project) def subscribers(project)
subscriptions_available(project). subscriptions_available(project)
where(subscribed: true). .where(subscribed: true)
map(&:user) .map(&:user)
end end
def toggle_subscription(user, project = nil) def toggle_subscription(user, project = nil)
unsubscribe_from_other_levels(user, project) unsubscribe_from_other_levels(user, project)
find_or_initialize_subscription(user, project). find_or_initialize_subscription(user, project)
update(subscribed: !subscribed?(user, project)) .update(subscribed: !subscribed?(user, project))
end end
def subscribe(user, project = nil) def subscribe(user, project = nil)
...@@ -69,14 +69,14 @@ module Subscribable ...@@ -69,14 +69,14 @@ module Subscribable
end end
def find_or_initialize_subscription(user, project) def find_or_initialize_subscription(user, project)
subscriptions. subscriptions
find_or_initialize_by(user_id: user.id, project_id: project.try(:id)) .find_or_initialize_by(user_id: user.id, project_id: project.try(:id))
end end
def subscriptions_available(project) def subscriptions_available(project)
t = Subscription.arel_table t = Subscription.arel_table
subscriptions. subscriptions
where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id)))) .where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id))))
end end
end end
...@@ -58,10 +58,10 @@ class Deployment < ActiveRecord::Base ...@@ -58,10 +58,10 @@ class Deployment < ActiveRecord::Base
def update_merge_request_metrics! def update_merge_request_metrics!
return unless environment.update_merge_request_metrics? return unless environment.update_merge_request_metrics?
merge_requests = project.merge_requests. merge_requests = project.merge_requests
joins(:metrics). .joins(:metrics)
where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }). .where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil })
where("merge_request_metrics.merged_at <= ?", self.created_at) .where("merge_request_metrics.merged_at <= ?", self.created_at)
if previous_deployment if previous_deployment
merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at) merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at)
...@@ -76,17 +76,17 @@ class Deployment < ActiveRecord::Base ...@@ -76,17 +76,17 @@ class Deployment < ActiveRecord::Base
merge_requests.map(&:id) merge_requests.map(&:id)
end end
MergeRequest::Metrics. MergeRequest::Metrics
where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil). .where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil)
update_all(first_deployed_to_production_at: self.created_at) .update_all(first_deployed_to_production_at: self.created_at)
end end
def previous_deployment def previous_deployment
@previous_deployment ||= @previous_deployment ||=
project.deployments.joins(:environment). project.deployments.joins(:environment)
where(environments: { name: self.environment.name }, ref: self.ref). .where(environments: { name: self.environment.name }, ref: self.ref)
where.not(id: self.id). .where.not(id: self.id)
take .take
end end
def stop_action def stop_action
......
...@@ -40,9 +40,9 @@ class Environment < ActiveRecord::Base ...@@ -40,9 +40,9 @@ class Environment < ActiveRecord::Base
scope :stopped, -> { with_state(:stopped) } scope :stopped, -> { with_state(:stopped) }
scope :order_by_last_deployed_at, -> do scope :order_by_last_deployed_at, -> do
max_deployment_id_sql = max_deployment_id_sql =
Deployment.select(Deployment.arel_table[:id].maximum). Deployment.select(Deployment.arel_table[:id].maximum)
where(Deployment.arel_table[:environment_id].eq(arel_table[:id])). .where(Deployment.arel_table[:environment_id].eq(arel_table[:id]))
to_sql .to_sql
order(Gitlab::Database.nulls_first_order("(#{max_deployment_id_sql})", 'ASC')) order(Gitlab::Database.nulls_first_order("(#{max_deployment_id_sql})", 'ASC'))
end end
......
...@@ -376,9 +376,9 @@ class Event < ActiveRecord::Base ...@@ -376,9 +376,9 @@ class Event < ActiveRecord::Base
# At this point it's possible for multiple threads/processes to try to # At this point it's possible for multiple threads/processes to try to
# update the project. Only one query should actually perform the update, # update the project. Only one query should actually perform the update,
# hence we add the extra WHERE clause for last_activity_at. # hence we add the extra WHERE clause for last_activity_at.
Project.unscoped.where(id: project_id). Project.unscoped.where(id: project_id)
where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago). .where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago)
update_all(last_activity_at: created_at) .update_all(last_activity_at: created_at)
end end
def authored_by?(user) def authored_by?(user)
...@@ -392,7 +392,7 @@ class Event < ActiveRecord::Base ...@@ -392,7 +392,7 @@ class Event < ActiveRecord::Base
end end
def set_last_repository_updated_at def set_last_repository_updated_at
Project.unscoped.where(id: project_id). Project.unscoped.where(id: project_id)
update_all(last_repository_updated_at: created_at) .update_all(last_repository_updated_at: created_at)
end end
end end
...@@ -206,8 +206,8 @@ class Group < Namespace ...@@ -206,8 +206,8 @@ class Group < Namespace
end end
def refresh_members_authorized_projects def refresh_members_authorized_projects
UserProjectAccessChangedService.new(user_ids_for_project_authorizations). UserProjectAccessChangedService.new(user_ids_for_project_authorizations)
execute .execute
end end
def user_ids_for_project_authorizations def user_ids_for_project_authorizations
...@@ -225,10 +225,10 @@ class Group < Namespace ...@@ -225,10 +225,10 @@ class Group < Namespace
def max_member_access_for_user(user) def max_member_access_for_user(user)
return GroupMember::OWNER if user.admin? return GroupMember::OWNER if user.admin?
members_with_parents. members_with_parents
where(user_id: user). .where(user_id: user)
reorder(access_level: :desc). .reorder(access_level: :desc)
first&. .first&.
access_level || GroupMember::NO_ACCESS access_level || GroupMember::NO_ACCESS
end end
......
...@@ -124,8 +124,8 @@ class Issue < ActiveRecord::Base ...@@ -124,8 +124,8 @@ class Issue < ActiveRecord::Base
end end
def self.order_by_position_and_priority def self.order_by_position_and_priority
order_labels_priority. order_labels_priority
reorder(Gitlab::Database.nulls_last_order('relative_position', 'ASC'), .reorder(Gitlab::Database.nulls_last_order('relative_position', 'ASC'),
Gitlab::Database.nulls_last_order('highest_priority', 'ASC'), Gitlab::Database.nulls_last_order('highest_priority', 'ASC'),
"id DESC") "id DESC")
end end
......
...@@ -17,9 +17,9 @@ class IssueCollection ...@@ -17,9 +17,9 @@ class IssueCollection
# Given all the issue projects we get a list of projects that the current # Given all the issue projects we get a list of projects that the current
# user has at least reporter access to. # user has at least reporter access to.
projects_with_reporter_access = user. projects_with_reporter_access = user
projects_with_reporter_access_limited_to(project_ids). .projects_with_reporter_access_limited_to(project_ids)
pluck(:id) .pluck(:id)
collection.select do |issue| collection.select do |issue|
if projects_with_reporter_access.include?(issue.project_id) if projects_with_reporter_access.include?(issue.project_id)
......
...@@ -46,9 +46,9 @@ class Label < ActiveRecord::Base ...@@ -46,9 +46,9 @@ class Label < ActiveRecord::Base
labels = Label.arel_table labels = Label.arel_table
priorities = LabelPriority.arel_table priorities = LabelPriority.arel_table
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin). label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin)
on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))). .on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id)))
join_sources .join_sources
joins(label_priorities).where(priorities[:priority].eq(nil)) joins(label_priorities).where(priorities[:priority].eq(nil))
end end
...@@ -57,9 +57,9 @@ class Label < ActiveRecord::Base ...@@ -57,9 +57,9 @@ class Label < ActiveRecord::Base
labels = Label.arel_table labels = Label.arel_table
priorities = LabelPriority.arel_table priorities = LabelPriority.arel_table
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin). label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin)
on(labels[:id].eq(priorities[:label_id])). .on(labels[:id].eq(priorities[:label_id]))
join_sources .join_sources
joins(label_priorities) joins(label_priorities)
end end
......
...@@ -99,9 +99,9 @@ class Member < ActiveRecord::Base ...@@ -99,9 +99,9 @@ class Member < ActiveRecord::Base
users = User.arel_table users = User.arel_table
members = Member.arel_table members = Member.arel_table
member_users = members.join(users, Arel::Nodes::OuterJoin). member_users = members.join(users, Arel::Nodes::OuterJoin)
on(members[:user_id].eq(users[:id])). .on(members[:user_id].eq(users[:id]))
join_sources .join_sources
joins(member_users) joins(member_users)
end end
......
...@@ -577,8 +577,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -577,8 +577,8 @@ class MergeRequest < ActiveRecord::Base
messages = [title, description] messages = [title, description]
messages.concat(commits.map(&:safe_message)) if merge_request_diff messages.concat(commits.map(&:safe_message)) if merge_request_diff
Gitlab::ClosingIssueExtractor.new(project, current_user). Gitlab::ClosingIssueExtractor.new(project, current_user)
closed_by_message(messages.join("\n")) .closed_by_message(messages.join("\n"))
else else
[] []
end end
......
...@@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base ...@@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base
class << self class << self
def count_for_collection(ids) def count_for_collection(ids)
group(:issue_id). group(:issue_id)
where(issue_id: ids). .where(issue_id: ids)
pluck('issue_id', 'COUNT(*) as count') .pluck('issue_id', 'COUNT(*) as count')
end end
end end
end end
...@@ -98,11 +98,11 @@ class Milestone < ActiveRecord::Base ...@@ -98,11 +98,11 @@ class Milestone < ActiveRecord::Base
if Gitlab::Database.postgresql? if Gitlab::Database.postgresql?
rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id') rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id')
else else
rel. rel
group(:project_id). .group(:project_id)
having('due_date = MIN(due_date)'). .having('due_date = MIN(due_date)')
pluck(:id, :project_id, :due_date). .pluck(:id, :project_id, :due_date)
map(&:first) .map(&:first)
end end
end end
......
...@@ -181,16 +181,16 @@ class Namespace < ActiveRecord::Base ...@@ -181,16 +181,16 @@ class Namespace < ActiveRecord::Base
def ancestors def ancestors
return self.class.none unless parent_id return self.class.none unless parent_id
Gitlab::GroupHierarchy. Gitlab::GroupHierarchy
new(self.class.where(id: parent_id)). .new(self.class.where(id: parent_id))
base_and_ancestors .base_and_ancestors
end end
# Returns all the descendants of the current namespace. # Returns all the descendants of the current namespace.
def descendants def descendants
Gitlab::GroupHierarchy. Gitlab::GroupHierarchy
new(self.class.where(parent_id: id)). .new(self.class.where(parent_id: id))
base_and_descendants .base_and_descendants
end end
def user_ids_for_project_authorizations def user_ids_for_project_authorizations
...@@ -253,10 +253,10 @@ class Namespace < ActiveRecord::Base ...@@ -253,10 +253,10 @@ class Namespace < ActiveRecord::Base
end end
def refresh_access_of_projects_invited_groups def refresh_access_of_projects_invited_groups
Group. Group
joins(project_group_links: :project). .joins(project_group_links: :project)
where(projects: { namespace_id: id }). .where(projects: { namespace_id: id })
find_each(&:refresh_members_authorized_projects) .find_each(&:refresh_members_authorized_projects)
end end
def remove_exports! def remove_exports!
......
...@@ -137,9 +137,9 @@ class Note < ActiveRecord::Base ...@@ -137,9 +137,9 @@ class Note < ActiveRecord::Base
end end
def count_for_collection(ids, type) def count_for_collection(ids, type)
user.select('noteable_id', 'COUNT(*) as count'). user.select('noteable_id', 'COUNT(*) as count')
group(:noteable_id). .group(:noteable_id)
where(noteable_type: type, noteable_id: ids) .where(noteable_type: type, noteable_id: ids)
end end
end end
......
...@@ -244,8 +244,8 @@ class Project < ActiveRecord::Base ...@@ -244,8 +244,8 @@ class Project < ActiveRecord::Base
scope :inside_path, ->(path) do scope :inside_path, ->(path) do
# We need routes alias rs for JOIN so it does not conflict with # We need routes alias rs for JOIN so it does not conflict with
# includes(:route) which we use in ProjectsFinder. # includes(:route) which we use in ProjectsFinder.
joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'"). joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'")
where('rs.path LIKE ?', "#{sanitize_sql_like(path)}/%") .where('rs.path LIKE ?', "#{sanitize_sql_like(path)}/%")
end end
# "enabled" here means "not disabled". It includes private features! # "enabled" here means "not disabled". It includes private features!
...@@ -270,10 +270,10 @@ class Project < ActiveRecord::Base ...@@ -270,10 +270,10 @@ class Project < ActiveRecord::Base
# logged in user. # logged in user.
def self.public_or_visible_to_user(user = nil) def self.public_or_visible_to_user(user = nil)
if user if user
authorized = user. authorized = user
project_authorizations. .project_authorizations
select(1). .select(1)
where('project_authorizations.project_id = projects.id') .where('project_authorizations.project_id = projects.id')
levels = Gitlab::VisibilityLevel.levels_for_user(user) levels = Gitlab::VisibilityLevel.levels_for_user(user)
...@@ -298,11 +298,11 @@ class Project < ActiveRecord::Base ...@@ -298,11 +298,11 @@ class Project < ActiveRecord::Base
elsif user elsif user
column = ProjectFeature.quoted_access_level_column(feature) column = ProjectFeature.quoted_access_level_column(feature)
authorized = user.project_authorizations.select(1). authorized = user.project_authorizations.select(1)
where('project_authorizations.project_id = projects.id') .where('project_authorizations.project_id = projects.id')
with_project_feature. with_project_feature
where("#{column} IN (?) OR (#{column} = ? AND EXISTS (?))", .where("#{column} IN (?) OR (#{column} = ? AND EXISTS (?))",
visible, visible,
ProjectFeature::PRIVATE, ProjectFeature::PRIVATE,
authorized) authorized)
...@@ -369,14 +369,14 @@ class Project < ActiveRecord::Base ...@@ -369,14 +369,14 @@ class Project < ActiveRecord::Base
# unscoping unnecessary conditions that'll be applied # unscoping unnecessary conditions that'll be applied
# when executing `where("projects.id IN (#{union.to_sql})")` # when executing `where("projects.id IN (#{union.to_sql})")`
projects = unscoped.select(:id).where( projects = unscoped.select(:id).where(
ptable[:path].matches(pattern). ptable[:path].matches(pattern)
or(ptable[:name].matches(pattern)). .or(ptable[:name].matches(pattern))
or(ptable[:description].matches(pattern)) .or(ptable[:description].matches(pattern))
) )
namespaces = unscoped.select(:id). namespaces = unscoped.select(:id)
joins(:namespace). .joins(:namespace)
where(ntable[:name].matches(pattern)) .where(ntable[:name].matches(pattern))
union = Gitlab::SQL::Union.new([projects, namespaces]) union = Gitlab::SQL::Union.new([projects, namespaces])
...@@ -417,8 +417,8 @@ class Project < ActiveRecord::Base ...@@ -417,8 +417,8 @@ class Project < ActiveRecord::Base
end end
def trending def trending
joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id'). joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id')
reorder('trending_projects.id ASC') .reorder('trending_projects.id ASC')
end end
def cached_count def cached_count
......
...@@ -7,9 +7,9 @@ class ProjectAuthorization < ActiveRecord::Base ...@@ -7,9 +7,9 @@ class ProjectAuthorization < ActiveRecord::Base
validates :user, uniqueness: { scope: [:project, :access_level] }, presence: true validates :user, uniqueness: { scope: [:project, :access_level] }, presence: true
def self.select_from_union(union) def self.select_from_union(union)
select(['project_id', 'MAX(access_level) AS access_level']). select(['project_id', 'MAX(access_level) AS access_level'])
from("(#{union.to_sql}) #{ProjectAuthorization.table_name}"). .from("(#{union.to_sql}) #{ProjectAuthorization.table_name}")
group(:project_id) .group(:project_id)
end end
def self.insert_authorizations(rows, per_batch = 1000) def self.insert_authorizations(rows, per_batch = 1000)
......
...@@ -20,8 +20,8 @@ class MattermostSlashCommandsService < SlashCommandsService ...@@ -20,8 +20,8 @@ class MattermostSlashCommandsService < SlashCommandsService
end end
def configure(user, params) def configure(user, params)
token = Mattermost::Command.new(user). token = Mattermost::Command.new(user)
create(command(params)) .create(command(params))
update(active: true, token: token) if token update(active: true, token: token) if token
rescue Mattermost::Error => e rescue Mattermost::Error => e
......
...@@ -172,10 +172,10 @@ class ProjectTeam ...@@ -172,10 +172,10 @@ class ProjectTeam
return access if user_ids.empty? return access if user_ids.empty?
users_access = project.project_authorizations. users_access = project.project_authorizations
where(user: user_ids). .where(user: user_ids)
group(:user_id). .group(:user_id)
maximum(:access_level) .maximum(:access_level)
access.merge!(users_access) access.merge!(users_access)
......
...@@ -241,11 +241,11 @@ class Repository ...@@ -241,11 +241,11 @@ class Repository
cache.fetch(:"diverging_commit_counts_#{branch.name}") do cache.fetch(:"diverging_commit_counts_#{branch.name}") do
# Rugged seems to throw a `ReferenceError` when given branch_names rather # Rugged seems to throw a `ReferenceError` when given branch_names rather
# than SHA-1 hashes # than SHA-1 hashes
number_commits_behind = raw_repository. number_commits_behind = raw_repository
count_commits_between(branch.dereferenced_target.sha, root_ref_hash) .count_commits_between(branch.dereferenced_target.sha, root_ref_hash)
number_commits_ahead = raw_repository. number_commits_ahead = raw_repository
count_commits_between(root_ref_hash, branch.dereferenced_target.sha) .count_commits_between(root_ref_hash, branch.dereferenced_target.sha)
{ behind: number_commits_behind, ahead: number_commits_ahead } { behind: number_commits_behind, ahead: number_commits_ahead }
end end
......
...@@ -70,9 +70,9 @@ class Todo < ActiveRecord::Base ...@@ -70,9 +70,9 @@ class Todo < ActiveRecord::Base
highest_priority = highest_label_priority(params).to_sql highest_priority = highest_label_priority(params).to_sql
select("#{table_name}.*, (#{highest_priority}) AS highest_priority"). select("#{table_name}.*, (#{highest_priority}) AS highest_priority")
order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')). .order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
order('todos.created_at') .order('todos.created_at')
end end
end end
......
...@@ -223,13 +223,13 @@ class User < ActiveRecord::Base ...@@ -223,13 +223,13 @@ class User < ActiveRecord::Base
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) } scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) }
def self.with_two_factor def self.with_two_factor
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id]) .where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id])
end end
def self.without_two_factor def self.without_two_factor
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
where("u2f.id IS NULL AND otp_required_for_login = ?", false) .where("u2f.id IS NULL AND otp_required_for_login = ?", false)
end end
# #
...@@ -300,9 +300,9 @@ class User < ActiveRecord::Base ...@@ -300,9 +300,9 @@ class User < ActiveRecord::Base
pattern = "%#{query}%" pattern = "%#{query}%"
where( where(
table[:name].matches(pattern). table[:name].matches(pattern)
or(table[:email].matches(pattern)). .or(table[:email].matches(pattern))
or(table[:username].matches(pattern)) .or(table[:username].matches(pattern))
) )
end end
...@@ -317,10 +317,10 @@ class User < ActiveRecord::Base ...@@ -317,10 +317,10 @@ class User < ActiveRecord::Base
matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern)) matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern))
where( where(
table[:name].matches(pattern). table[:name].matches(pattern)
or(table[:email].matches(pattern)). .or(table[:email].matches(pattern))
or(table[:username].matches(pattern)). .or(table[:username].matches(pattern))
or(table[:id].in(matched_by_emails_user_ids)) .or(table[:id].in(matched_by_emails_user_ids))
) )
end end
...@@ -503,8 +503,8 @@ class User < ActiveRecord::Base ...@@ -503,8 +503,8 @@ class User < ActiveRecord::Base
# Returns the groups a user has access to # Returns the groups a user has access to
def authorized_groups def authorized_groups
union = Gitlab::SQL::Union. union = Gitlab::SQL::Union
new([groups.select(:id), authorized_projects.select(:namespace_id)]) .new([groups.select(:id), authorized_projects.select(:namespace_id)])
Group.where("namespaces.id IN (#{union.to_sql})") Group.where("namespaces.id IN (#{union.to_sql})")
end end
...@@ -533,8 +533,8 @@ class User < ActiveRecord::Base ...@@ -533,8 +533,8 @@ class User < ActiveRecord::Base
projects = super() projects = super()
if min_access_level if min_access_level
projects = projects. projects = projects
where('project_authorizations.access_level >= ?', min_access_level) .where('project_authorizations.access_level >= ?', min_access_level)
end end
projects projects
...@@ -619,9 +619,9 @@ class User < ActiveRecord::Base ...@@ -619,9 +619,9 @@ class User < ActiveRecord::Base
next unless project next unless project
if project.repository.branch_exists?(event.branch_name) if project.repository.branch_exists?(event.branch_name)
merge_requests = MergeRequest.where("created_at >= ?", event.created_at). merge_requests = MergeRequest.where("created_at >= ?", event.created_at)
where(source_project_id: project.id, .where(source_project_id: project.id,
source_branch: event.branch_name) source_branch: event.branch_name)
merge_requests.empty? merge_requests.empty?
end end
end end
...@@ -832,8 +832,8 @@ class User < ActiveRecord::Base ...@@ -832,8 +832,8 @@ class User < ActiveRecord::Base
def toggle_star(project) def toggle_star(project)
UsersStarProject.transaction do UsersStarProject.transaction do
user_star_project = users_star_projects. user_star_project = users_star_projects
where(project: project, user: self).lock(true).first .where(project: project, user: self).lock(true).first
if user_star_project if user_star_project
user_star_project.destroy user_star_project.destroy
...@@ -869,11 +869,11 @@ class User < ActiveRecord::Base ...@@ -869,11 +869,11 @@ class User < ActiveRecord::Base
# ms on a database with a similar size to GitLab.com's database. On the other # ms on a database with a similar size to GitLab.com's database. On the other
# hand, using a subquery means we can get the exact same data in about 40 ms. # hand, using a subquery means we can get the exact same data in about 40 ms.
def contributed_projects def contributed_projects
events = Event.select(:project_id). events = Event.select(:project_id)
contributions.where(author_id: self). .contributions.where(author_id: self)
where("created_at > ?", Time.now - 1.year). .where("created_at > ?", Time.now - 1.year)
uniq. .uniq
reorder(nil) .reorder(nil)
Project.where(id: events) Project.where(id: events)
end end
...@@ -884,9 +884,9 @@ class User < ActiveRecord::Base ...@@ -884,9 +884,9 @@ class User < ActiveRecord::Base
def ci_authorized_runners def ci_authorized_runners
@ci_authorized_runners ||= begin @ci_authorized_runners ||= begin
runner_ids = Ci::RunnerProject. runner_ids = Ci::RunnerProject
where("ci_runner_projects.project_id IN (#{ci_projects_union.to_sql})"). .where("ci_runner_projects.project_id IN (#{ci_projects_union.to_sql})")
select(:runner_id) .select(:runner_id)
Ci::Runner.specific.where(id: runner_ids) Ci::Runner.specific.where(id: runner_ids)
end end
end end
......
...@@ -22,16 +22,16 @@ class WikiPage ...@@ -22,16 +22,16 @@ class WikiPage
def self.group_by_directory(pages) def self.group_by_directory(pages)
return [] if pages.blank? return [] if pages.blank?
pages.sort_by { |page| [page.directory, page.slug] }. pages.sort_by { |page| [page.directory, page.slug] }
group_by(&:directory). .group_by(&:directory)
map do |dir, pages| .map do |dir, pages|
if dir.present? if dir.present?
WikiDirectory.new(dir, pages) WikiDirectory.new(dir, pages)
else else
pages pages
end end
end. end
flatten .flatten
end end
def self.unhyphenize(name) def self.unhyphenize(name)
......
...@@ -67,8 +67,8 @@ module Ci ...@@ -67,8 +67,8 @@ module Ci
def update_merge_requests_head_pipeline def update_merge_requests_head_pipeline
return unless pipeline.latest? return unless pipeline.latest?
MergeRequest.where(source_project: @pipeline.project, source_branch: @pipeline.ref). MergeRequest.where(source_project: @pipeline.project, source_branch: @pipeline.ref)
update_all(head_pipeline_id: @pipeline.id) .update_all(head_pipeline_id: @pipeline.id)
end end
def skip_ci? def skip_ci?
......
...@@ -3,8 +3,8 @@ module Ci ...@@ -3,8 +3,8 @@ module Ci
def execute(project, trigger, ref, variables = nil) def execute(project, trigger, ref, variables = nil)
trigger_request = trigger.trigger_requests.create(variables: variables) trigger_request = trigger.trigger_requests.create(variables: variables)
pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: ref). pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: ref)
execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request) .execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request)
trigger_request if pipeline.persisted? trigger_request if pipeline.persisted?
end end
......
...@@ -54,15 +54,15 @@ module Ci ...@@ -54,15 +54,15 @@ module Ci
def builds_for_shared_runner def builds_for_shared_runner
new_builds. new_builds.
# don't run projects which have not enabled shared runners and builds # don't run projects which have not enabled shared runners and builds
joins(:project).where(projects: { shared_runners_enabled: true }). joins(:project).where(projects: { shared_runners_enabled: true })
joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id'). .joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id')
where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0'). .where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
# Implement fair scheduling # Implement fair scheduling
# this returns builds that are ordered by number of running builds # this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all # we prefer projects that don't use shared runners at all
joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id"). joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id")
order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC') .order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
end end
def builds_for_specific_runner def builds_for_specific_runner
...@@ -70,8 +70,8 @@ module Ci ...@@ -70,8 +70,8 @@ module Ci
end end
def running_builds_for_shared_runners def running_builds_for_shared_runners
Ci::Build.running.where(runner: Ci::Runner.shared). Ci::Build.running.where(runner: Ci::Runner.shared)
group(:project_id).select(:project_id, 'count(*) AS running_builds') .group(:project_id).select(:project_id, 'count(*) AS running_builds')
end end
def new_builds def new_builds
......
...@@ -10,9 +10,9 @@ module Issues ...@@ -10,9 +10,9 @@ module Issues
def merge_request_to_resolve_discussions_of def merge_request_to_resolve_discussions_of
return @merge_request_to_resolve_discussions_of if defined?(@merge_request_to_resolve_discussions_of) return @merge_request_to_resolve_discussions_of if defined?(@merge_request_to_resolve_discussions_of)
@merge_request_to_resolve_discussions_of = MergeRequestsFinder.new(current_user, project_id: project.id). @merge_request_to_resolve_discussions_of = MergeRequestsFinder.new(current_user, project_id: project.id)
execute. .execute
find_by(iid: merge_request_to_resolve_discussions_of_iid) .find_by(iid: merge_request_to_resolve_discussions_of_iid)
end end
def discussions_to_resolve def discussions_to_resolve
......
...@@ -28,8 +28,8 @@ module Files ...@@ -28,8 +28,8 @@ module Files
end end
def last_commit def last_commit
@last_commit ||= Gitlab::Git::Commit. @last_commit ||= Gitlab::Git::Commit
last_for_path(@start_project.repository, @start_branch, @file_path) .last_for_path(@start_project.repository, @start_branch, @file_path)
end end
def validate! def validate!
......
...@@ -86,8 +86,8 @@ class GitPushService < BaseService ...@@ -86,8 +86,8 @@ class GitPushService < BaseService
push_commits.last(PROCESS_COMMIT_LIMIT).each do |commit| push_commits.last(PROCESS_COMMIT_LIMIT).each do |commit|
if commit.matches_cross_reference_regex? if commit.matches_cross_reference_regex?
ProcessCommitWorker. ProcessCommitWorker
perform_async(project.id, current_user.id, commit.to_hash, default) .perform_async(project.id, current_user.id, commit.to_hash, default)
end end
end end
end end
......
...@@ -144,8 +144,8 @@ class IssuableBaseService < BaseService ...@@ -144,8 +144,8 @@ class IssuableBaseService < BaseService
def merge_quick_actions_into_params!(issuable) def merge_quick_actions_into_params!(issuable)
description, command_params = description, command_params =
QuickActions::InterpretService.new(project, current_user). QuickActions::InterpretService.new(project, current_user)
execute(params[:description], issuable) .execute(params[:description], issuable)
# Avoid a description already set on an issuable to be overwritten by a nil # Avoid a description already set on an issuable to be overwritten by a nil
params[:description] = description if params.key?(:description) params[:description] = description if params.key?(:description)
......
...@@ -30,8 +30,8 @@ module Issues ...@@ -30,8 +30,8 @@ module Issues
Discussions::ResolveService.new(project, current_user, Discussions::ResolveService.new(project, current_user,
merge_request: merge_request_to_resolve_discussions_of, merge_request: merge_request_to_resolve_discussions_of,
follow_up_issue: issue). follow_up_issue: issue)
execute(discussions_to_resolve) .execute(discussions_to_resolve)
end end
private private
......
...@@ -26,29 +26,29 @@ module Labels ...@@ -26,29 +26,29 @@ module Labels
private private
def label_ids_for_merge(new_label) def label_ids_for_merge(new_label)
LabelsFinder. LabelsFinder
new(current_user, title: new_label.title, group_id: project.group.id). .new(current_user, title: new_label.title, group_id: project.group.id)
execute(skip_authorization: true). .execute(skip_authorization: true)
where.not(id: new_label). .where.not(id: new_label)
select(:id) # Can't use pluck() to avoid object-creation because of the batching .select(:id) # Can't use pluck() to avoid object-creation because of the batching
end end
def update_issuables(new_label, label_ids) def update_issuables(new_label, label_ids)
LabelLink. LabelLink
where(label: label_ids). .where(label: label_ids)
update_all(label_id: new_label) .update_all(label_id: new_label)
end end
def update_issue_board_lists(new_label, label_ids) def update_issue_board_lists(new_label, label_ids)
List. List
where(label: label_ids). .where(label: label_ids)
update_all(label_id: new_label) .update_all(label_id: new_label)
end end
def update_priorities(new_label, label_ids) def update_priorities(new_label, label_ids)
LabelPriority. LabelPriority
where(label: label_ids). .where(label: label_ids)
update_all(label_id: new_label) .update_all(label_id: new_label)
end end
def update_project_labels(label_ids) def update_project_labels(label_ids)
......
...@@ -41,16 +41,16 @@ module Labels ...@@ -41,16 +41,16 @@ module Labels
end end
def group_labels_applied_to_issues def group_labels_applied_to_issues
Label.joins(:issues). Label.joins(:issues)
where( .where(
issues: { project_id: project.id }, issues: { project_id: project.id },
labels: { type: 'GroupLabel', group_id: old_group.id } labels: { type: 'GroupLabel', group_id: old_group.id }
) )
end end
def group_labels_applied_to_merge_requests def group_labels_applied_to_merge_requests
Label.joins(:merge_requests). Label.joins(:merge_requests)
where( .where(
merge_requests: { target_project_id: project.id }, merge_requests: { target_project_id: project.id },
labels: { type: 'GroupLabel', group_id: old_group.id } labels: { type: 'GroupLabel', group_id: old_group.id }
) )
...@@ -64,15 +64,15 @@ module Labels ...@@ -64,15 +64,15 @@ module Labels
end end
def update_label_links(labels, old_label_id:, new_label_id:) def update_label_links(labels, old_label_id:, new_label_id:)
LabelLink.joins(:label). LabelLink.joins(:label)
merge(labels). .merge(labels)
where(label_id: old_label_id). .where(label_id: old_label_id)
update_all(label_id: new_label_id) .update_all(label_id: new_label_id)
end end
def update_label_priorities(old_label_id:, new_label_id:) def update_label_priorities(old_label_id:, new_label_id:)
LabelPriority.where(project_id: project.id, label_id: old_label_id). LabelPriority.where(project_id: project.id, label_id: old_label_id)
update_all(label_id: new_label_id) .update_all(label_id: new_label_id)
end end
end end
end end
...@@ -26,30 +26,30 @@ module Members ...@@ -26,30 +26,30 @@ module Members
def unassign_issues_and_merge_requests(member) def unassign_issues_and_merge_requests(member)
if member.is_a?(GroupMember) if member.is_a?(GroupMember)
issues = Issue.unscoped.select(1). issues = Issue.unscoped.select(1)
joins(:project). .joins(:project)
where('issues.id = issue_assignees.issue_id AND projects.namespace_id = ?', member.source_id) .where('issues.id = issue_assignees.issue_id AND projects.namespace_id = ?', member.source_id)
# DELETE FROM issue_assignees WHERE user_id = X AND EXISTS (...) # DELETE FROM issue_assignees WHERE user_id = X AND EXISTS (...)
IssueAssignee.unscoped. IssueAssignee.unscoped
where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues). .where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues)
delete_all .delete_all
MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id)
execute. .execute
update_all(assignee_id: nil) .update_all(assignee_id: nil)
else else
project = member.source project = member.source
# SELECT 1 FROM issues WHERE issues.id = issue_assignees.issue_id AND issues.project_id = X # SELECT 1 FROM issues WHERE issues.id = issue_assignees.issue_id AND issues.project_id = X
issues = Issue.unscoped.select(1). issues = Issue.unscoped.select(1)
where('issues.id = issue_assignees.issue_id'). .where('issues.id = issue_assignees.issue_id')
where(project_id: project.id) .where(project_id: project.id)
# DELETE FROM issue_assignees WHERE user_id = X AND EXISTS (...) # DELETE FROM issue_assignees WHERE user_id = X AND EXISTS (...)
IssueAssignee.unscoped. IssueAssignee.unscoped
where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues). .where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues)
delete_all .delete_all
project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil) project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil)
end end
......
...@@ -27,10 +27,10 @@ module MergeRequests ...@@ -27,10 +27,10 @@ module MergeRequests
tree: merge_index.write_tree(rugged) tree: merge_index.write_tree(rugged)
} }
conflicts_for_resolution. conflicts_for_resolution
project. .project
repository. .repository
resolve_conflicts(current_user, merge_request.source_branch, commit_params) .resolve_conflicts(current_user, merge_request.source_branch, commit_params)
end end
end end
......
...@@ -61,8 +61,8 @@ module MergeRequests ...@@ -61,8 +61,8 @@ module MergeRequests
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request) MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
if params[:should_remove_source_branch].present? || @merge_request.force_remove_source_branch? if params[:should_remove_source_branch].present? || @merge_request.force_remove_source_branch?
DeleteBranchService.new(@merge_request.source_project, branch_deletion_user). DeleteBranchService.new(@merge_request.source_project, branch_deletion_user)
execute(merge_request.source_branch) .execute(merge_request.source_branch)
end end
end end
......
...@@ -43,9 +43,9 @@ module MergeRequests ...@@ -43,9 +43,9 @@ module MergeRequests
end end
filter_merge_requests(merge_requests).each do |merge_request| filter_merge_requests(merge_requests).each do |merge_request|
MergeRequests::PostMergeService. MergeRequests::PostMergeService
new(merge_request.target_project, @current_user). .new(merge_request.target_project, @current_user)
execute(merge_request) .execute(merge_request)
end end
end end
...@@ -56,8 +56,8 @@ module MergeRequests ...@@ -56,8 +56,8 @@ module MergeRequests
# Refresh merge request diff if we push to source or target branch of merge request # Refresh merge request diff if we push to source or target branch of merge request
# Note: we should update merge requests from forks too # Note: we should update merge requests from forks too
def reload_merge_requests def reload_merge_requests
merge_requests = @project.merge_requests.opened. merge_requests = @project.merge_requests.opened
by_source_or_target_branch(@branch_name).to_a .by_source_or_target_branch(@branch_name).to_a
# Fork merge requests # Fork merge requests
merge_requests += MergeRequest.opened merge_requests += MergeRequest.opened
......
...@@ -22,8 +22,8 @@ module Notes ...@@ -22,8 +22,8 @@ module Notes
def extract_commands(note, options = {}) def extract_commands(note, options = {})
return [note.note, {}] unless supported?(note) return [note.note, {}] unless supported?(note)
QuickActions::InterpretService.new(project, current_user, options). QuickActions::InterpretService.new(project, current_user, options)
execute(note.note, note.noteable) .execute(note.note, note.noteable)
end end
def execute(command_params, note) def execute(command_params, note)
......
...@@ -19,8 +19,8 @@ module Tags ...@@ -19,8 +19,8 @@ module Tags
if new_tag if new_tag
if release_description if release_description
CreateReleaseService.new(@project, @current_user). CreateReleaseService.new(@project, @current_user)
execute(tag_name, release_description) .execute(tag_name, release_description)
end end
success.merge(tag: new_tag) success.merge(tag: new_tag)
......
...@@ -7,7 +7,7 @@ class MergeWorker ...@@ -7,7 +7,7 @@ class MergeWorker
current_user = User.find(current_user_id) current_user = User.find(current_user_id)
merge_request = MergeRequest.find(merge_request_id) merge_request = MergeRequest.find(merge_request_id)
MergeRequests::MergeService.new(merge_request.target_project, current_user, params). MergeRequests::MergeService.new(merge_request.target_project, current_user, params)
execute(merge_request) .execute(merge_request)
end end
end end
...@@ -47,8 +47,8 @@ class ProcessCommitWorker ...@@ -47,8 +47,8 @@ class ProcessCommitWorker
# therefor we use IssueCollection here and skip the authorization check in # therefor we use IssueCollection here and skip the authorization check in
# Issues::CloseService#execute. # Issues::CloseService#execute.
IssueCollection.new(issues).updatable_by_user(user).each do |issue| IssueCollection.new(issues).updatable_by_user(user).each do |issue|
Issues::CloseService.new(project, author). Issues::CloseService.new(project, author)
close_issue(issue, commit: commit) .close_issue(issue, commit: commit)
end end
end end
...@@ -57,8 +57,8 @@ class ProcessCommitWorker ...@@ -57,8 +57,8 @@ class ProcessCommitWorker
return if mentioned_issues.empty? return if mentioned_issues.empty?
Issue::Metrics.where(issue_id: mentioned_issues.map(&:id), first_mentioned_in_commit_at: nil). Issue::Metrics.where(issue_id: mentioned_issues.map(&:id), first_mentioned_in_commit_at: nil)
update_all(first_mentioned_in_commit_at: commit.committed_date) .update_all(first_mentioned_in_commit_at: commit.committed_date)
end end
def build_commit(project, hash) def build_commit(project, hash)
......
...@@ -32,8 +32,8 @@ class ProjectCacheWorker ...@@ -32,8 +32,8 @@ class ProjectCacheWorker
private private
def try_obtain_lease_for(project_id, section) def try_obtain_lease_for(project_id, section)
Gitlab::ExclusiveLease. Gitlab::ExclusiveLease
new("project_cache_worker:#{project_id}:#{section}", timeout: LEASE_TIMEOUT). .new("project_cache_worker:#{project_id}:#{section}", timeout: LEASE_TIMEOUT)
try_obtain .try_obtain
end end
end end
...@@ -14,8 +14,8 @@ class PropagateServiceTemplateWorker ...@@ -14,8 +14,8 @@ class PropagateServiceTemplateWorker
private private
def try_obtain_lease_for(template_id) def try_obtain_lease_for(template_id)
Gitlab::ExclusiveLease. Gitlab::ExclusiveLease
new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT). .new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT)
try_obtain .try_obtain
end end
end end
...@@ -10,9 +10,9 @@ class PruneOldEventsWorker ...@@ -10,9 +10,9 @@ class PruneOldEventsWorker
'(id IN (SELECT id FROM (?) ids_to_remove))', '(id IN (SELECT id FROM (?) ids_to_remove))',
Event.unscoped.where( Event.unscoped.where(
'created_at < ?', 'created_at < ?',
(12.months + 1.day).ago). (12.months + 1.day).ago)
select(:id). .select(:id)
limit(10_000)). .limit(10_000))
delete_all .delete_all
end end
end end
...@@ -32,10 +32,10 @@ module RepositoryCheck ...@@ -32,10 +32,10 @@ module RepositoryCheck
# has to sit and wait for this query to finish. # has to sit and wait for this query to finish.
def project_ids def project_ids
limit = 10_000 limit = 10_000
never_checked_projects = Project.where('last_repository_check_at IS NULL AND created_at < ?', 24.hours.ago). never_checked_projects = Project.where('last_repository_check_at IS NULL AND created_at < ?', 24.hours.ago)
limit(limit).pluck(:id) .limit(limit).pluck(:id)
old_check_projects = Project.where('last_repository_check_at < ?', 1.month.ago). old_check_projects = Project.where('last_repository_check_at < ?', 1.month.ago)
reorder('last_repository_check_at ASC').limit(limit).pluck(:id) .reorder('last_repository_check_at ASC').limit(limit).pluck(:id)
never_checked_projects + old_check_projects never_checked_projects + old_check_projects
end end
......
...@@ -7,8 +7,8 @@ class UpdateUserActivityWorker ...@@ -7,8 +7,8 @@ class UpdateUserActivityWorker
ids = pairs.keys ids = pairs.keys
conditions = 'WHEN id = ? THEN ? ' * ids.length conditions = 'WHEN id = ? THEN ? ' * ids.length
User.where(id: ids). User.where(id: ids)
update_all([ .update_all([
"last_activity_on = CASE #{conditions} ELSE last_activity_on END", "last_activity_on = CASE #{conditions} ELSE last_activity_on END",
*pairs.to_a.flatten *pairs.to_a.flatten
]) ])
......
...@@ -154,8 +154,8 @@ if Gitlab::Metrics.enabled? ...@@ -154,8 +154,8 @@ if Gitlab::Metrics.enabled?
ActiveRecord::Querying.public_instance_methods(false).map(&:to_s) ActiveRecord::Querying.public_instance_methods(false).map(&:to_s)
) )
Gitlab::Metrics::Instrumentation. Gitlab::Metrics::Instrumentation
instrument_class_hierarchy(ActiveRecord::Base) do |klass, method| .instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
# Instrumenting the ApplicationSetting class can lead to an infinite # Instrumenting the ApplicationSetting class can lead to an infinite
# loop. Since the data is cached any way we don't really need to # loop. Since the data is cached any way we don't really need to
# instrument it. # instrument it.
......
...@@ -6,9 +6,9 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration ...@@ -6,9 +6,9 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration
class Project < ActiveRecord::Base class Project < ActiveRecord::Base
def self.find_including_path(id) def self.find_including_path(id)
select("projects.*, CONCAT(namespaces.path, '/', projects.path) AS path_with_namespace"). select("projects.*, CONCAT(namespaces.path, '/', projects.path) AS path_with_namespace")
joins('INNER JOIN namespaces ON namespaces.id = projects.namespace_id'). .joins('INNER JOIN namespaces ON namespaces.id = projects.namespace_id')
find_by(id: id) .find_by(id: id)
end end
def repository_storage_path def repository_storage_path
......
...@@ -8,11 +8,11 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration ...@@ -8,11 +8,11 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration
environments = Arel::Table.new(:environments) environments = Arel::Table.new(:environments)
# Get all [project_id, name] pairs that occur more than once # Get all [project_id, name] pairs that occur more than once
finder_sql = environments. finder_sql = environments
group(environments[:project_id], environments[:name]). .group(environments[:project_id], environments[:name])
having(Arel.sql("COUNT(1)").gt(1)). .having(Arel.sql("COUNT(1)").gt(1))
project(environments[:project_id], environments[:name]). .project(environments[:project_id], environments[:name])
to_sql .to_sql
conflicting = connection.exec_query(finder_sql) conflicting = connection.exec_query(finder_sql)
...@@ -28,12 +28,12 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration ...@@ -28,12 +28,12 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration
# Rename conflicting environments by appending "-#{id}" to all but the first # Rename conflicting environments by appending "-#{id}" to all but the first
def fix_duplicates(project_id, name) def fix_duplicates(project_id, name)
environments = Arel::Table.new(:environments) environments = Arel::Table.new(:environments)
finder_sql = environments. finder_sql = environments
where(environments[:project_id].eq(project_id)). .where(environments[:project_id].eq(project_id))
where(environments[:name].eq(name)). .where(environments[:name].eq(name))
order(environments[:id].asc). .order(environments[:id].asc)
project(environments[:id], environments[:name]). .project(environments[:id], environments[:name])
to_sql .to_sql
# Now we have the data for all the conflicting rows # Now we have the data for all the conflicting rows
conflicts = connection.exec_query(finder_sql).rows conflicts = connection.exec_query(finder_sql).rows
...@@ -41,11 +41,11 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration ...@@ -41,11 +41,11 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration
conflicts.each do |id, name| conflicts.each do |id, name|
update_sql = update_sql =
Arel::UpdateManager.new(ActiveRecord::Base). Arel::UpdateManager.new(ActiveRecord::Base)
table(environments). .table(environments)
set(environments[:name] => name + "-" + id.to_s). .set(environments[:name] => name + "-" + id.to_s)
where(environments[:id].eq(id)). .where(environments[:id].eq(id))
to_sql .to_sql
connection.exec_update(update_sql, self.class.name, []) connection.exec_update(update_sql, self.class.name, [])
end end
......
...@@ -19,10 +19,10 @@ class AddEnvironmentSlug < ActiveRecord::Migration ...@@ -19,10 +19,10 @@ class AddEnvironmentSlug < ActiveRecord::Migration
finder = environments.project(:id, :name) finder = environments.project(:id, :name)
connection.exec_query(finder.to_sql).rows.each do |id, name| connection.exec_query(finder.to_sql).rows.each do |id, name|
updater = Arel::UpdateManager.new(ActiveRecord::Base). updater = Arel::UpdateManager.new(ActiveRecord::Base)
table(environments). .table(environments)
set(environments[:slug] => generate_slug(name)). .set(environments[:slug] => generate_slug(name))
where(environments[:id].eq(id)) .where(environments[:id].eq(id))
connection.exec_update(updater.to_sql, self.class.name, []) connection.exec_update(updater.to_sql, self.class.name, [])
end end
......
...@@ -159,9 +159,9 @@ class RenameSystemNamespaces < ActiveRecord::Migration ...@@ -159,9 +159,9 @@ class RenameSystemNamespaces < ActiveRecord::Migration
end end
def system_namespace def system_namespace
@system_namespace ||= Namespace.where(parent_id: nil). @system_namespace ||= Namespace.where(parent_id: nil)
where(arel_table[:path].matches(system_namespace_path)). .where(arel_table[:path].matches(system_namespace_path))
first .first
end end
def system_namespace_path def system_namespace_path
...@@ -209,8 +209,8 @@ class RenameSystemNamespaces < ActiveRecord::Migration ...@@ -209,8 +209,8 @@ class RenameSystemNamespaces < ActiveRecord::Migration
end end
def repo_paths_for_namespace(namespace) def repo_paths_for_namespace(namespace)
projects_for_namespace(namespace).distinct. projects_for_namespace(namespace).distinct
select(:repository_storage).map(&:repository_storage_path) .select(:repository_storage).map(&:repository_storage_path)
end end
def uploads_dir def uploads_dir
......
...@@ -87,8 +87,8 @@ class TurnNestedGroupsIntoRegularGroupsForMysql < ActiveRecord::Migration ...@@ -87,8 +87,8 @@ class TurnNestedGroupsIntoRegularGroupsForMysql < ActiveRecord::Migration
while current&.parent_id while current&.parent_id
# We're using find_by(id: ...) here to deal with cases where the # We're using find_by(id: ...) here to deal with cases where the
# parent_id may point to a missing row. # parent_id may point to a missing row.
current = Namespace.unscoped.select([:id, :parent_id]). current = Namespace.unscoped.select([:id, :parent_id])
find_by(id: current.parent_id) .find_by(id: current.parent_id)
ancestors << current.id if current ancestors << current.id if current
end end
...@@ -99,11 +99,11 @@ class TurnNestedGroupsIntoRegularGroupsForMysql < ActiveRecord::Migration ...@@ -99,11 +99,11 @@ class TurnNestedGroupsIntoRegularGroupsForMysql < ActiveRecord::Migration
# Returns a relation containing all the members that have access to any of # Returns a relation containing all the members that have access to any of
# the current namespace's parent namespaces. # the current namespace's parent namespaces.
def all_members_for(namespace) def all_members_for(namespace)
Member. Member
unscoped. .unscoped
select(['user_id', 'MAX(access_level) AS access_level']). .select(['user_id', 'MAX(access_level) AS access_level'])
where(source_type: 'Namespace', source_id: ancestors_for(namespace)). .where(source_type: 'Namespace', source_id: ancestors_for(namespace))
group(:user_id) .group(:user_id)
end end
def bulk_insert_members(rows) def bulk_insert_members(rows)
......
...@@ -13,13 +13,13 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration ...@@ -13,13 +13,13 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration
namespaces = Arel::Table.new(:namespaces) namespaces = Arel::Table.new(:namespaces)
finder_sql = finder_sql =
projects. projects
join(namespaces, Arel::Nodes::InnerJoin). .join(namespaces, Arel::Nodes::InnerJoin)
on(projects[:namespace_id].eq(namespaces[:id])). .on(projects[:namespace_id].eq(namespaces[:id]))
where(projects[:visibility_level].gt(namespaces[:visibility_level])). .where(projects[:visibility_level].gt(namespaces[:visibility_level]))
project(projects[:id], namespaces[:visibility_level]). .project(projects[:id], namespaces[:visibility_level])
take(BATCH_SIZE). .take(BATCH_SIZE)
to_sql .to_sql
# Update matching rows in batches. Each batch can cause up to 3 UPDATE # Update matching rows in batches. Each batch can cause up to 3 UPDATE
# statements, in addition to the SELECT: one per visibility_level # statements, in addition to the SELECT: one per visibility_level
...@@ -33,10 +33,10 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration ...@@ -33,10 +33,10 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration
end end
updates.each do |visibility_level, project_ids| updates.each do |visibility_level, project_ids|
updater = Arel::UpdateManager.new(ActiveRecord::Base). updater = Arel::UpdateManager.new(ActiveRecord::Base)
table(projects). .table(projects)
set(projects[:visibility_level] => visibility_level). .set(projects[:visibility_level] => visibility_level)
where(projects[:id].in(project_ids)) .where(projects[:id].in(project_ids))
ActiveRecord::Base.connection.exec_update(updater.to_sql, self.class.name, []) ActiveRecord::Base.connection.exec_update(updater.to_sql, self.class.name, [])
end end
......
...@@ -79,17 +79,17 @@ class RenameReservedProjectNames < ActiveRecord::Migration ...@@ -79,17 +79,17 @@ class RenameReservedProjectNames < ActiveRecord::Migration
private private
def reserved_projects def reserved_projects
Project.unscoped. Project.unscoped
includes(:namespace). .includes(:namespace)
where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)'). .where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)')
where('projects.path' => KNOWN_PATHS) .where('projects.path' => KNOWN_PATHS)
end end
def route_exists?(full_path) def route_exists?(full_path)
quoted_path = ActiveRecord::Base.connection.quote_string(full_path) quoted_path = ActiveRecord::Base.connection.quote_string(full_path)
ActiveRecord::Base.connection. ActiveRecord::Base.connection
select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present? .select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present?
end end
# Adds number to the end of the path that is not taken by other route # Adds number to the end of the path that is not taken by other route
......
...@@ -39,11 +39,11 @@ class RequeuePendingDeleteProjects < ActiveRecord::Migration ...@@ -39,11 +39,11 @@ class RequeuePendingDeleteProjects < ActiveRecord::Migration
def find_batch def find_batch
projects = Arel::Table.new(:projects) projects = Arel::Table.new(:projects)
projects.project(projects[:id]). projects.project(projects[:id])
where(projects[:pending_delete].eq(true)). .where(projects[:pending_delete].eq(true))
where(projects[:namespace_id].not_eq(nil)). .where(projects[:namespace_id].not_eq(nil))
skip(@offset * BATCH_SIZE). .skip(@offset * BATCH_SIZE)
take(BATCH_SIZE). .take(BATCH_SIZE)
to_sql .to_sql
end end
end end
...@@ -15,8 +15,8 @@ class FillAuthorizedProjects < ActiveRecord::Migration ...@@ -15,8 +15,8 @@ class FillAuthorizedProjects < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
def up def up
relation = User.select(:id). relation = User.select(:id)
where('authorized_projects_populated IS NOT TRUE') .where('authorized_projects_populated IS NOT TRUE')
relation.find_in_batches(batch_size: 1_000) do |rows| relation.find_in_batches(batch_size: 1_000) do |rows|
args = rows.map { |row| [row.id] } args = rows.map { |row| [row.id] }
......
...@@ -21,17 +21,17 @@ class RenameMoreReservedProjectNames < ActiveRecord::Migration ...@@ -21,17 +21,17 @@ class RenameMoreReservedProjectNames < ActiveRecord::Migration
private private
def reserved_projects def reserved_projects
Project.unscoped. Project.unscoped
includes(:namespace). .includes(:namespace)
where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)'). .where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)')
where('projects.path' => KNOWN_PATHS) .where('projects.path' => KNOWN_PATHS)
end end
def route_exists?(full_path) def route_exists?(full_path)
quoted_path = ActiveRecord::Base.connection.quote_string(full_path) quoted_path = ActiveRecord::Base.connection.quote_string(full_path)
ActiveRecord::Base.connection. ActiveRecord::Base.connection
select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present? .select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present?
end end
# Adds number to the end of the path that is not taken by other route # Adds number to the end of the path that is not taken by other route
......
...@@ -38,11 +38,11 @@ class MigrateUserActivitiesToUsersLastActivityOn < ActiveRecord::Migration ...@@ -38,11 +38,11 @@ class MigrateUserActivitiesToUsersLastActivityOn < ActiveRecord::Migration
activities = activities(day.at_beginning_of_day, day.at_end_of_day, page: page) activities = activities(day.at_beginning_of_day, day.at_end_of_day, page: page)
update_sql = update_sql =
Arel::UpdateManager.new(ActiveRecord::Base). Arel::UpdateManager.new(ActiveRecord::Base)
table(users_table). .table(users_table)
set(users_table[:last_activity_on] => day.to_date). .set(users_table[:last_activity_on] => day.to_date)
where(users_table[:username].in(activities.map(&:first))). .where(users_table[:username].in(activities.map(&:first)))
to_sql .to_sql
connection.exec_update(update_sql, self.class.name, []) connection.exec_update(update_sql, self.class.name, [])
......
...@@ -37,11 +37,11 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration ...@@ -37,11 +37,11 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration
def find_batch def find_batch
projects = Arel::Table.new(:projects) projects = Arel::Table.new(:projects)
projects.project(projects[:id]). projects.project(projects[:id])
where(projects[:pending_delete].eq(true)). .where(projects[:pending_delete].eq(true))
where(projects[:namespace_id].eq(nil)). .where(projects[:namespace_id].eq(nil))
skip(@offset * BATCH_SIZE). .skip(@offset * BATCH_SIZE)
take(BATCH_SIZE). .take(BATCH_SIZE)
to_sql .to_sql
end end
end end
...@@ -9,11 +9,11 @@ class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration ...@@ -9,11 +9,11 @@ class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration
pipelines = Arel::Table.new(:ci_pipelines) pipelines = Arel::Table.new(:ci_pipelines)
merge_requests = Arel::Table.new(:merge_requests) merge_requests = Arel::Table.new(:merge_requests)
head_id = pipelines. head_id = pipelines
project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]])). .project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]]))
from(pipelines). .from(pipelines)
where(pipelines[:ref].eq(merge_requests[:source_branch])). .where(pipelines[:ref].eq(merge_requests[:source_branch]))
where(pipelines[:project_id].eq(merge_requests[:source_project_id])) .where(pipelines[:project_id].eq(merge_requests[:source_project_id]))
sub_query = Arel::Nodes::SqlLiteral.new(Arel::Nodes::Grouping.new(head_id).to_sql) sub_query = Arel::Nodes::SqlLiteral.new(Arel::Nodes::Grouping.new(head_id).to_sql)
......
...@@ -68,8 +68,8 @@ module API ...@@ -68,8 +68,8 @@ module API
delete ":id/access_requests/:user_id" do delete ":id/access_requests/:user_id" do
source = find_source(source_type, params[:id]) source = find_source(source_type, params[:id])
::Members::DestroyService.new(source, current_user, params). ::Members::DestroyService.new(source, current_user, params)
execute(:requesters) .execute(:requesters)
end end
end end
end end
......
...@@ -102,8 +102,8 @@ module API ...@@ -102,8 +102,8 @@ module API
post ":id/repository/branches" do post ":id/repository/branches" do
authorize_push_project authorize_push_project
result = CreateBranchService.new(user_project, current_user). result = CreateBranchService.new(user_project, current_user)
execute(params[:branch], params[:ref]) .execute(params[:branch], params[:ref])
if result[:status] == :success if result[:status] == :success
present result[:branch], present result[:branch],
...@@ -121,8 +121,8 @@ module API ...@@ -121,8 +121,8 @@ module API
delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do
authorize_push_project authorize_push_project
result = DeleteBranchService.new(user_project, current_user). result = DeleteBranchService.new(user_project, current_user)
execute(params[:branch]) .execute(params[:branch])
if result[:status] != :success if result[:status] != :success
render_api_error!(result[:message], result[:return_code]) render_api_error!(result[:message], result[:return_code])
......
...@@ -484,9 +484,9 @@ module API ...@@ -484,9 +484,9 @@ module API
expose :job_events expose :job_events
# Expose serialized properties # Expose serialized properties
expose :properties do |service, options| expose :properties do |service, options|
field_names = service.fields. field_names = service.fields
select { |field| options[:include_passwords] || field[:type] != 'password' }. .select { |field| options[:include_passwords] || field[:type] != 'password' }
map { |field| field[:name] } .map { |field| field[:name] }
service.properties.slice(*field_names) service.properties.slice(*field_names)
end end
end end
......
...@@ -33,8 +33,8 @@ module API ...@@ -33,8 +33,8 @@ module API
# paginate() only works with a relation. This could lead to a # paginate() only works with a relation. This could lead to a
# mismatch between the pagination headers info and the actual notes # mismatch between the pagination headers info and the actual notes
# array returned, but this is really a edge-case. # array returned, but this is really a edge-case.
paginate(noteable.notes). paginate(noteable.notes)
reject { |n| n.cross_reference_not_visible_for?(current_user) } .reject { |n| n.cross_reference_not_visible_for?(current_user) }
present notes, with: Entities::Note present notes, with: Entities::Note
else else
not_found!("Notes") not_found!("Notes")
......
...@@ -44,8 +44,8 @@ module API ...@@ -44,8 +44,8 @@ module API
post ':id/repository/tags' do post ':id/repository/tags' do
authorize_push_project authorize_push_project
result = ::Tags::CreateService.new(user_project, current_user). result = ::Tags::CreateService.new(user_project, current_user)
execute(params[:tag_name], params[:ref], params[:message], params[:release_description]) .execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
if result[:status] == :success if result[:status] == :success
present result[:tag], present result[:tag],
...@@ -63,8 +63,8 @@ module API ...@@ -63,8 +63,8 @@ module API
delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
result = ::Tags::DestroyService.new(user_project, current_user). result = ::Tags::DestroyService.new(user_project, current_user)
execute(params[:tag_name]) .execute(params[:tag_name])
if result[:status] != :success if result[:status] != :success
render_api_error!(result[:message], result[:return_code]) render_api_error!(result[:message], result[:return_code])
...@@ -81,8 +81,8 @@ module API ...@@ -81,8 +81,8 @@ module API
post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
result = CreateReleaseService.new(user_project, current_user). result = CreateReleaseService.new(user_project, current_user)
execute(params[:tag_name], params[:description]) .execute(params[:tag_name], params[:description])
if result[:status] == :success if result[:status] == :success
present result[:release], with: Entities::Release present result[:release], with: Entities::Release
...@@ -101,8 +101,8 @@ module API ...@@ -101,8 +101,8 @@ module API
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
result = UpdateReleaseService.new(user_project, current_user). result = UpdateReleaseService.new(user_project, current_user)
execute(params[:tag_name], params[:description]) .execute(params[:tag_name], params[:description])
if result[:status] == :success if result[:status] == :success
present result[:release], with: Entities::Release present result[:release], with: Entities::Release
......
...@@ -103,13 +103,13 @@ module API ...@@ -103,13 +103,13 @@ module API
if user.persisted? if user.persisted?
present user, with: Entities::UserPublic present user, with: Entities::UserPublic
else else
conflict!('Email has already been taken') if User. conflict!('Email has already been taken') if User
where(email: user.email). .where(email: user.email)
count > 0 .count > 0
conflict!('Username has already been taken') if User. conflict!('Username has already been taken') if User
where(username: user.username). .where(username: user.username)
count > 0 .count > 0
render_validation_error!(user) render_validation_error!(user)
end end
...@@ -133,12 +133,12 @@ module API ...@@ -133,12 +133,12 @@ module API
not_found!('User') unless user not_found!('User') unless user
conflict!('Email has already been taken') if params[:email] && conflict!('Email has already been taken') if params[:email] &&
User.where(email: params[:email]). User.where(email: params[:email])
where.not(id: user.id).count > 0 .where.not(id: user.id).count > 0
conflict!('Username has already been taken') if params[:username] && conflict!('Username has already been taken') if params[:username] &&
User.where(username: params[:username]). User.where(username: params[:username])
where.not(id: user.id).count > 0 .where.not(id: user.id).count > 0
user_params = declared_params(include_missing: false) user_params = declared_params(include_missing: false)
identity_attrs = user_params.slice(:provider, :extern_uid) identity_attrs = user_params.slice(:provider, :extern_uid)
...@@ -517,9 +517,9 @@ module API ...@@ -517,9 +517,9 @@ module API
get "activities" do get "activities" do
authenticated_as_admin! authenticated_as_admin!
activities = User. activities = User
where(User.arel_table[:last_activity_on].gteq(params[:from])). .where(User.arel_table[:last_activity_on].gteq(params[:from]))
reorder(last_activity_on: :asc) .reorder(last_activity_on: :asc)
present paginate(activities), with: Entities::UserActivity present paginate(activities), with: Entities::UserActivity
end end
......
...@@ -26,8 +26,8 @@ module API ...@@ -26,8 +26,8 @@ module API
delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do
authorize_push_project authorize_push_project
result = DeleteBranchService.new(user_project, current_user). result = DeleteBranchService.new(user_project, current_user)
execute(params[:branch]) .execute(params[:branch])
if result[:status] == :success if result[:status] == :success
status(200) status(200)
...@@ -55,8 +55,8 @@ module API ...@@ -55,8 +55,8 @@ module API
end end
post ":id/repository/branches" do post ":id/repository/branches" do
authorize_push_project authorize_push_project
result = CreateBranchService.new(user_project, current_user). result = CreateBranchService.new(user_project, current_user)
execute(params[:branch_name], params[:ref]) .execute(params[:branch_name], params[:ref])
if result[:status] == :success if result[:status] == :success
present result[:branch], present result[:branch],
......
...@@ -245,9 +245,9 @@ module API ...@@ -245,9 +245,9 @@ module API
expose :job_events, as: :build_events expose :job_events, as: :build_events
# Expose serialized properties # Expose serialized properties
expose :properties do |service, options| expose :properties do |service, options|
field_names = service.fields. field_names = service.fields
select { |field| options[:include_passwords] || field[:type] != 'password' }. .select { |field| options[:include_passwords] || field[:type] != 'password' }
map { |field| field[:name] } .map { |field| field[:name] }
service.properties.slice(*field_names) service.properties.slice(*field_names)
end end
end end
......
...@@ -34,8 +34,8 @@ module API ...@@ -34,8 +34,8 @@ module API
# paginate() only works with a relation. This could lead to a # paginate() only works with a relation. This could lead to a
# mismatch between the pagination headers info and the actual notes # mismatch between the pagination headers info and the actual notes
# array returned, but this is really a edge-case. # array returned, but this is really a edge-case.
paginate(noteable.notes). paginate(noteable.notes)
reject { |n| n.cross_reference_not_visible_for?(current_user) } .reject { |n| n.cross_reference_not_visible_for?(current_user) }
present notes, with: ::API::V3::Entities::Note present notes, with: ::API::V3::Entities::Note
else else
not_found!("Notes") not_found!("Notes")
......
...@@ -22,8 +22,8 @@ module API ...@@ -22,8 +22,8 @@ module API
delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
result = ::Tags::DestroyService.new(user_project, current_user). result = ::Tags::DestroyService.new(user_project, current_user)
execute(params[:tag_name]) .execute(params[:tag_name])
if result[:status] == :success if result[:status] == :success
status(200) status(200)
......
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.
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.
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.
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