Commit 1be5430d authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'remove_for_id' into 'master'

Remove for_ids scope

See merge request gitlab-org/gitlab!54897
parents b0edafe7 bba41afc
......@@ -52,7 +52,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def bulk_restore
TodoService.new.restore_todos(current_user.todos.for_ids(params[:ids]), current_user)
TodoService.new.restore_todos(current_user.todos.id_in(params[:ids]), current_user)
render json: todos_counts
end
......
......@@ -32,7 +32,7 @@ module Projects
# rubocop: disable CodeReuse/ActiveRecord
def builds
@builds ||= pipeline.latest_builds.for_ids(build_ids).presence || render_404
@builds ||= pipeline.latest_builds.id_in(build_ids).presence || render_404
end
def build_ids
......
......@@ -60,7 +60,7 @@ module Mutations
def authorized_find_all_pending_by_current_user(ids)
return Todo.none if ids.blank? || current_user.nil?
Todo.for_ids(ids).for_user(current_user).done
Todo.id_in(ids).for_user(current_user).done
end
def restore(todos)
......
......@@ -52,7 +52,6 @@ class CommitStatus < ApplicationRecord
scope :before_stage, -> (index) { where('stage_idx < ?', index) }
scope :for_stage, -> (index) { where(stage_idx: index) }
scope :after_stage, -> (index) { where('stage_idx > ?', index) }
scope :for_ids, -> (ids) { where(id: ids) }
scope :for_ref, -> (ref) { where(ref: ref) }
scope :by_name, -> (name) { where(name: name) }
scope :in_pipelines, ->(pipelines) { where(pipeline: pipelines) }
......
......@@ -55,7 +55,6 @@ class Todo < ApplicationRecord
validates :project, presence: true, unless: :group_id
validates :group, presence: true, unless: :project_id
scope :for_ids, -> (ids) { where(id: ids) }
scope :pending, -> { with_state(:pending) }
scope :done, -> { with_state(:done) }
scope :for_action, -> (action) { where(action: action) }
......
......@@ -53,7 +53,7 @@ module Ci
end
def update_processables!(ids)
created_processables = pipeline.processables.for_ids(ids)
created_processables = pipeline.processables.id_in(ids)
.with_project_preload
.created
.latest
......
......@@ -45,7 +45,7 @@ module EE
def epics
if params[:include_subepics]
::Gitlab::ObjectHierarchy.new(::Epic.for_ids(params[:epic_id])).base_and_descendants.select(:id)
::Gitlab::ObjectHierarchy.new(::Epic.id_in(params[:epic_id])).base_and_descendants.select(:id)
else
params[:epic_id]
end
......
......@@ -19,7 +19,7 @@ module Resolvers
context.scoped_set!(:board, board)
Epic.for_ids(board_epic_ids(args[:issue_filters]))
Epic.id_in(board_epic_ids(args[:issue_filters]))
end
private
......
......@@ -67,7 +67,6 @@ module EE
alias_attribute :parent_ids, :parent_id
alias_method :issuing_parent, :group
scope :for_ids, -> (ids) { where(id: ids) }
scope :in_parents, -> (parent_ids) { where(parent_id: parent_ids) }
scope :inc_group, -> { includes(:group) }
scope :in_selected_groups, -> (groups) { where(group_id: groups) }
......@@ -274,11 +273,11 @@ module EE
end
def ids_for_base_and_decendants(epic_ids)
::Gitlab::ObjectHierarchy.new(self.for_ids(epic_ids)).base_and_descendants.pluck(:id)
::Gitlab::ObjectHierarchy.new(self.id_in(epic_ids)).base_and_descendants.pluck(:id)
end
def issue_metadata_for_epics(epic_ids:, limit:)
records = self.for_ids(epic_ids)
records = self.id_in(epic_ids)
.left_joins(epic_issues: :issue)
.group("epics.id", "epics.iid", "epics.parent_id", "epics.state_id", "issues.state_id")
.select("epics.id, epics.iid, epics.parent_id, epics.state_id AS epic_state_id, issues.state_id AS issues_state_id, COUNT(issues) AS issues_count, SUM(COALESCE(issues.weight, 0)) AS issues_weight_sum")
......
......@@ -9,7 +9,7 @@ module EE
override :find_issuables
def find_issuables(parent, model_class, ids)
return model_class.for_ids(ids).in_selected_groups(parent.self_and_descendants) if model_class == ::Epic
return model_class.id_in(ids).in_selected_groups(parent.self_and_descendants) if model_class == ::Epic
super
end
......
......@@ -11,7 +11,7 @@ module Epics
def initialize(epics)
@epics = epics
@epics = Epic.for_ids(@epics) unless @epics.is_a?(ActiveRecord::Relation)
@epics = Epic.id_in(@epics) unless @epics.is_a?(ActiveRecord::Relation)
end
def execute
......
......@@ -10,7 +10,7 @@ module Epics
def perform(epic_ids)
return if epic_ids.blank?
Epics::UpdateDatesService.new(Epic.for_ids(epic_ids)).execute
Epics::UpdateDatesService.new(Epic.id_in(epic_ids)).execute
end
end
end
......@@ -363,23 +363,6 @@ RSpec.describe Todo do
end
end
describe '.for_ids' do
it 'returns the expected todos' do
todo1 = create(:todo)
todo2 = create(:todo)
todo3 = create(:todo)
create(:todo)
expect(described_class.for_ids([todo2.id, todo1.id, todo3.id])).to contain_exactly(todo1, todo2, todo3)
end
it 'returns an empty collection when no ids are given' do
create(:todo)
expect(described_class.for_ids([])).to be_empty
end
end
describe '.for_user' do
it 'returns the expected todos' do
user1 = create(:user)
......
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