Commit bba41afc authored by Jan Provaznik's avatar Jan Provaznik

Remove for_ids scope

There is `id_in` method which can be used instead.
parent be67fa62
...@@ -52,7 +52,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -52,7 +52,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end end
def bulk_restore 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 render json: todos_counts
end end
......
...@@ -32,7 +32,7 @@ module Projects ...@@ -32,7 +32,7 @@ module Projects
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def builds 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 end
def build_ids def build_ids
......
...@@ -60,7 +60,7 @@ module Mutations ...@@ -60,7 +60,7 @@ module Mutations
def authorized_find_all_pending_by_current_user(ids) def authorized_find_all_pending_by_current_user(ids)
return Todo.none if ids.blank? || current_user.nil? 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 end
def restore(todos) def restore(todos)
......
...@@ -52,7 +52,6 @@ class CommitStatus < ApplicationRecord ...@@ -52,7 +52,6 @@ class CommitStatus < ApplicationRecord
scope :before_stage, -> (index) { where('stage_idx < ?', index) } scope :before_stage, -> (index) { where('stage_idx < ?', index) }
scope :for_stage, -> (index) { where(stage_idx: index) } scope :for_stage, -> (index) { where(stage_idx: index) }
scope :after_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 :for_ref, -> (ref) { where(ref: ref) }
scope :by_name, -> (name) { where(name: name) } scope :by_name, -> (name) { where(name: name) }
scope :in_pipelines, ->(pipelines) { where(pipeline: pipelines) } scope :in_pipelines, ->(pipelines) { where(pipeline: pipelines) }
......
...@@ -55,7 +55,6 @@ class Todo < ApplicationRecord ...@@ -55,7 +55,6 @@ class Todo < ApplicationRecord
validates :project, presence: true, unless: :group_id validates :project, presence: true, unless: :group_id
validates :group, presence: true, unless: :project_id validates :group, presence: true, unless: :project_id
scope :for_ids, -> (ids) { where(id: ids) }
scope :pending, -> { with_state(:pending) } scope :pending, -> { with_state(:pending) }
scope :done, -> { with_state(:done) } scope :done, -> { with_state(:done) }
scope :for_action, -> (action) { where(action: action) } scope :for_action, -> (action) { where(action: action) }
......
...@@ -53,7 +53,7 @@ module Ci ...@@ -53,7 +53,7 @@ module Ci
end end
def update_processables!(ids) def update_processables!(ids)
created_processables = pipeline.processables.for_ids(ids) created_processables = pipeline.processables.id_in(ids)
.with_project_preload .with_project_preload
.created .created
.latest .latest
......
...@@ -45,7 +45,7 @@ module EE ...@@ -45,7 +45,7 @@ module EE
def epics def epics
if params[:include_subepics] 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 else
params[:epic_id] params[:epic_id]
end end
......
...@@ -19,7 +19,7 @@ module Resolvers ...@@ -19,7 +19,7 @@ module Resolvers
context.scoped_set!(:board, board) context.scoped_set!(:board, board)
Epic.for_ids(board_epic_ids(args[:issue_filters])) Epic.id_in(board_epic_ids(args[:issue_filters]))
end end
private private
......
...@@ -67,7 +67,6 @@ module EE ...@@ -67,7 +67,6 @@ module EE
alias_attribute :parent_ids, :parent_id alias_attribute :parent_ids, :parent_id
alias_method :issuing_parent, :group alias_method :issuing_parent, :group
scope :for_ids, -> (ids) { where(id: ids) }
scope :in_parents, -> (parent_ids) { where(parent_id: parent_ids) } scope :in_parents, -> (parent_ids) { where(parent_id: parent_ids) }
scope :inc_group, -> { includes(:group) } scope :inc_group, -> { includes(:group) }
scope :in_selected_groups, -> (groups) { where(group_id: groups) } scope :in_selected_groups, -> (groups) { where(group_id: groups) }
...@@ -274,11 +273,11 @@ module EE ...@@ -274,11 +273,11 @@ module EE
end end
def ids_for_base_and_decendants(epic_ids) 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 end
def issue_metadata_for_epics(epic_ids:, limit:) 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) .left_joins(epic_issues: :issue)
.group("epics.id", "epics.iid", "epics.parent_id", "epics.state_id", "issues.state_id") .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") .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 ...@@ -9,7 +9,7 @@ module EE
override :find_issuables override :find_issuables
def find_issuables(parent, model_class, ids) 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 super
end end
......
...@@ -11,7 +11,7 @@ module Epics ...@@ -11,7 +11,7 @@ module Epics
def initialize(epics) def initialize(epics)
@epics = 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 end
def execute def execute
......
...@@ -10,7 +10,7 @@ module Epics ...@@ -10,7 +10,7 @@ module Epics
def perform(epic_ids) def perform(epic_ids)
return if epic_ids.blank? 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 end
end end
...@@ -363,23 +363,6 @@ RSpec.describe Todo do ...@@ -363,23 +363,6 @@ RSpec.describe Todo do
end end
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 describe '.for_user' do
it 'returns the expected todos' do it 'returns the expected todos' do
user1 = create(:user) 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