Commit 66ce587c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'revert-e421e0c1' into 'master'

Revert "Merge branch '21068-optimize-issueable-updates' into 'master'"

See merge request gitlab-org/gitlab!59355
parents 44fac22d 1cd2df17
...@@ -137,14 +137,6 @@ module Issuable ...@@ -137,14 +137,6 @@ module Issuable
scope :references_project, -> { references(:project) } scope :references_project, -> { references(:project) }
scope :non_archived, -> { join_project.where(projects: { archived: false }) } scope :non_archived, -> { join_project.where(projects: { archived: false }) }
scope :includes_for_bulk_update, -> do
associations = %i[author assignees epic group labels metrics project source_project target_project].select do |association|
reflect_on_association(association)
end
includes(*associations)
end
attr_mentionable :title, pipeline: :single_line attr_mentionable :title, pipeline: :single_line
attr_mentionable :description attr_mentionable :description
......
...@@ -39,13 +39,11 @@ module Milestoneable ...@@ -39,13 +39,11 @@ module Milestoneable
private private
def milestone_is_valid def milestone_is_valid
errors.add(:milestone_id, 'is invalid') if respond_to?(:milestone_id) && !milestone_available? errors.add(:milestone_id, 'is invalid') if respond_to?(:milestone_id) && milestone_id.present? && !milestone_available?
end end
end end
def milestone_available? def milestone_available?
return true if milestone_id.blank?
project_id == milestone&.project_id || project.ancestors_upto.compact.include?(milestone&.group) project_id == milestone&.project_id || project.ancestors_upto.compact.include?(milestone&.group)
end end
......
...@@ -15,7 +15,7 @@ module Issuable ...@@ -15,7 +15,7 @@ module Issuable
set_update_params(type) set_update_params(type)
items = update_issuables(type, ids) items = update_issuables(type, ids)
response_success(payload: { count: items.size }) response_success(payload: { count: items.count })
rescue ArgumentError => e rescue ArgumentError => e
response_error(e.message, 422) response_error(e.message, 422)
end end
...@@ -59,17 +59,10 @@ module Issuable ...@@ -59,17 +59,10 @@ module Issuable
def find_issuables(parent, model_class, ids) def find_issuables(parent, model_class, ids)
if parent.is_a?(Project) if parent.is_a?(Project)
projects = parent model_class.id_in(ids).of_projects(parent)
elsif parent.is_a?(Group) elsif parent.is_a?(Group)
projects = parent.all_projects model_class.id_in(ids).of_projects(parent.all_projects)
else
return
end end
model_class
.id_in(ids)
.of_projects(projects)
.includes_for_bulk_update
end end
def response_success(message: nil, payload: nil) def response_success(message: nil, payload: nil)
......
---
title: Optimize issuable updates
merge_request: 58114
author:
type: performance
...@@ -9,12 +9,9 @@ module EE ...@@ -9,12 +9,9 @@ module EE
override :find_issuables override :find_issuables
def find_issuables(parent, model_class, ids) def find_issuables(parent, model_class, ids)
return super unless model_class == ::Epic return model_class.id_in(ids).in_selected_groups(parent.self_and_descendants) if model_class == ::Epic
model_class super
.id_in(ids)
.in_selected_groups(parent.self_and_descendants)
.includes_for_bulk_update
end end
override :permitted_attrs override :permitted_attrs
......
...@@ -204,11 +204,13 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::RequestParams do ...@@ -204,11 +204,13 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::RequestParams do
subject { described_class.new(params).to_data_attributes } subject { described_class.new(params).to_data_attributes }
it { expect(subject[:milestone]).to eq('title') } it "has the correct attributes" do
it { expect(subject[:assignees]).to eq('["username1"]') } expect(subject[:milestone]).to eq('title')
it { expect(subject[:labels]).to eq('["label1","label2"]') } expect(subject[:assignees]).to eq('["username1"]')
it { expect(subject[:author]).to eq('author') } expect(subject[:labels]).to eq('["label1","label2"]')
it { expect(subject[:stage]).to eq('{"id":1,"title":"Stage #1"}') } expect(subject[:author]).to eq('author')
expect(subject[:stage]).to eq(%Q|{"id":#{stage.id},"title":"#{stage.name}"}|)
end
end end
describe 'sorting params' do describe 'sorting params' do
......
...@@ -4,11 +4,11 @@ require 'spec_helper' ...@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe EE::Milestoneable do RSpec.describe EE::Milestoneable do
describe '#milestone_available?' do describe '#milestone_available?' do
context 'for epics' do context 'no Epic' do
let(:epic) { build(:epic) } let(:issue) { create(:issue) }
it 'returns true' do it 'returns false' do
expect(epic.milestone_available?).to be(true) expect(issue.milestone_available?).to be_falsy
end end
end end
end end
...@@ -21,7 +21,7 @@ RSpec.describe EE::Milestoneable do ...@@ -21,7 +21,7 @@ RSpec.describe EE::Milestoneable do
let(:epic) { build(:epic) } let(:epic) { build(:epic) }
it 'returns false' do it 'returns false' do
expect(epic.supports_milestone?).to be(false) expect(epic.supports_milestone?).to be_falsy
end end
end end
end end
......
...@@ -65,23 +65,6 @@ RSpec.describe Issuable do ...@@ -65,23 +65,6 @@ RSpec.describe Issuable do
it { expect(issuable_class).to respond_to(:opened) } it { expect(issuable_class).to respond_to(:opened) }
it { expect(issuable_class).to respond_to(:closed) } it { expect(issuable_class).to respond_to(:closed) }
it { expect(issuable_class).to respond_to(:assigned) } it { expect(issuable_class).to respond_to(:assigned) }
describe '.includes_for_bulk_update' do
before do
stub_const('Example', Class.new(ActiveRecord::Base))
Example.class_eval do
include Issuable # adds :labels and :metrics, among others
belongs_to :author
has_many :assignees
end
end
it 'includes available associations' do
expect(Example.includes_for_bulk_update.includes_values).to eq([:author, :assignees, :labels, :metrics])
end
end
end end
describe 'author_name' do describe 'author_name' do
......
...@@ -50,13 +50,13 @@ RSpec.describe Milestoneable do ...@@ -50,13 +50,13 @@ RSpec.describe Milestoneable do
it 'returns true with a milestone from the issue project' do it 'returns true with a milestone from the issue project' do
milestone = create(:milestone, project: project) milestone = create(:milestone, project: project)
expect(build_milestoneable(milestone.id).milestone_available?).to be(true) expect(build_milestoneable(milestone.id).milestone_available?).to be_truthy
end end
it 'returns true with a milestone from the issue project group' do it 'returns true with a milestone from the issue project group' do
milestone = create(:milestone, group: group) milestone = create(:milestone, group: group)
expect(build_milestoneable(milestone.id).milestone_available?).to be(true) expect(build_milestoneable(milestone.id).milestone_available?).to be_truthy
end end
it 'returns true with a milestone from the the parent of the issue project group' do it 'returns true with a milestone from the the parent of the issue project group' do
...@@ -64,23 +64,19 @@ RSpec.describe Milestoneable do ...@@ -64,23 +64,19 @@ RSpec.describe Milestoneable do
group.update!(parent: parent) group.update!(parent: parent)
milestone = create(:milestone, group: parent) milestone = create(:milestone, group: parent)
expect(build_milestoneable(milestone.id).milestone_available?).to be(true) expect(build_milestoneable(milestone.id).milestone_available?).to be_truthy
end
it 'returns true with a blank milestone' do
expect(build_milestoneable('').milestone_available?).to be(true)
end end
it 'returns false with a milestone from another project' do it 'returns false with a milestone from another project' do
milestone = create(:milestone) milestone = create(:milestone)
expect(build_milestoneable(milestone.id).milestone_available?).to be(false) expect(build_milestoneable(milestone.id).milestone_available?).to be_falsey
end end
it 'returns false with a milestone from another group' do it 'returns false with a milestone from another group' do
milestone = create(:milestone, group: create(:group)) milestone = create(:milestone, group: create(:group))
expect(build_milestoneable(milestone.id).milestone_available?).to be(false) expect(build_milestoneable(milestone.id).milestone_available?).to be_falsey
end end
end end
end end
......
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