Commit 322336c3 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '281703-remove-blockeed-by' into 'master'

Remove is_blocked_by

See merge request gitlab-org/gitlab!51448
parents 2b7f667c 2ebcd8f4
......@@ -22,67 +22,35 @@ module EE
end
def blocked_issue_ids(issue_ids)
blocked_and_blocking_issues_union(issue_ids).pluck(:blocked_issue_id)
blocked_or_blocking_issues(issue_ids).pluck(:target_id)
end
def blocking_issue_ids_for(issue)
blocked_and_blocking_issues_union(issue.id).pluck(:blocking_issue_id)
blocked_or_blocking_issues(issue.id).pluck(:source_id)
end
def blocked_and_blocking_issues_union(issue_ids)
from_union([
blocked_or_blocking_issues(issue_ids, ::IssueLink::TYPE_BLOCKS),
blocked_or_blocking_issues(issue_ids, ::IssueLink::TYPE_IS_BLOCKED_BY)
])
end
def blocked_or_blocking_issues(issue_ids, link_type)
if link_type == ::IssueLink::TYPE_BLOCKS
blocked_key = :target_id
blocking_key = :source_id
else
blocked_key = :source_id
blocking_key = :target_id
end
select("#{blocked_key} as blocked_issue_id, #{blocking_key} as blocking_issue_id")
.where(link_type: link_type).where(blocked_key => issue_ids)
.joins("INNER JOIN issues ON issues.id = issue_links.#{blocking_key}")
.where('issues.state_id' => ::Issuable::STATE_ID_MAP[:opened])
def blocked_or_blocking_issues(issue_ids)
where(link_type: ::IssueLink::TYPE_BLOCKS).where(target_id: issue_ids)
.joins(:source)
.where(issues: { state_id: ::Issue.available_states[:opened] })
end
def blocking_issues_for_collection(issues_ids)
open_state_id = ::Issuable::STATE_ID_MAP[:opened]
from_union([
select("COUNT(CASE WHEN issues.state_id = #{open_state_id} then 1 else null end), issue_links.source_id AS blocking_issue_id")
.joins(:target)
.where(link_type: ::IssueLink::TYPE_BLOCKS)
.where(source_id: issues_ids)
.group(:blocking_issue_id),
select("COUNT(CASE WHEN issues.state_id = #{open_state_id} then 1 else null end), issue_links.target_id AS blocking_issue_id")
.joins(:source)
.where(link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
.where(target_id: issues_ids)
.group(:blocking_issue_id)
], remove_duplicates: false).select('blocking_issue_id, SUM(count) AS count').group('blocking_issue_id')
select("COUNT(CASE WHEN issues.state_id = #{open_state_id} then 1 else null end), issue_links.source_id AS blocking_issue_id")
.joins(:target)
.where(link_type: ::IssueLink::TYPE_BLOCKS, source_id: issues_ids)
.group(:blocking_issue_id)
end
def blocked_issues_for_collection(issues_ids)
from_union([
select('COUNT(*), issue_links.source_id AS blocked_issue_id')
.joins(:target)
.where(issues: { state_id: ::Issue.available_states[:opened] })
.where(link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
.where(source_id: issues_ids)
.group(:blocked_issue_id),
select('COUNT(*), issue_links.target_id AS blocked_issue_id')
.joins(:source)
.where(issues: { state_id: ::Issue.available_states[:opened] })
.where(link_type: ::IssueLink::TYPE_BLOCKS)
.where(target_id: issues_ids)
.group(:blocked_issue_id)
], remove_duplicates: false).select('blocked_issue_id, SUM(count) AS count').group('blocked_issue_id')
select('COUNT(*), issue_links.target_id AS blocked_issue_id')
.joins(:source)
.where(issues: { state_id: ::Issue.available_states[:opened] })
.where(link_type: ::IssueLink::TYPE_BLOCKS)
.where(target_id: issues_ids)
.group(:blocked_issue_id)
end
def blocking_issues_count_for(issue)
......@@ -93,10 +61,7 @@ module EE
private
def blocking_issue
case link_type
when ::IssueLink::TYPE_BLOCKS then source
when ::IssueLink::TYPE_IS_BLOCKED_BY then target
end
source if link_type == ::IssueLink::TYPE_BLOCKS
end
def refresh_blocking_issue_cache
......
......@@ -57,9 +57,9 @@ RSpec.describe Boards::IssuesController do
issue4 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 4)
closed_issue = create(:issue, :closed, project: project_1)
create(:issue_link, source: issue1, target: issue2, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: issue2, target: issue1, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue2, target: issue3, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue4, target: closed_issue, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: closed_issue, target: issue4, link_type: IssueLink::TYPE_BLOCKS)
list_issues user: user, board: board, list: list2
......
......@@ -30,7 +30,7 @@ RSpec.describe GitlabSchema.types['Issue'] do
blocked_issue2 = create(:issue, project: project)
blocking_issue2 = create(:issue, project: project)
create :issue_link, source: blocked_issue2, target: blocking_issue2, link_type: IssueLink::TYPE_IS_BLOCKED_BY
create :issue_link, source: blocking_issue2, target: blocked_issue2, link_type: IssueLink::TYPE_BLOCKS
project2 = create(:project, :public, group: group)
create(:issue, project: project2)
......
......@@ -21,7 +21,7 @@ RSpec.describe Gitlab::IssuableMetadata do
create(:issue_link, source: blocking_issue_1, target: blocked_issue_1, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: blocking_issue_2, target: blocked_issue_2, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: blocking_issue_1, target: closed_blocked_issue, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: blocked_issue_3, target: blocking_issue_1, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: blocking_issue_1, target: blocked_issue_3, link_type: IssueLink::TYPE_BLOCKS)
end
it 'aggregates stats on issues' do
......
......@@ -17,15 +17,6 @@ RSpec.describe IssueLink do
end
end
context 'with TYPE_IS_BLOCKED_BY' do
it 'updates blocking issues count' do
expect(source).not_to receive(:update_blocking_issues_count!)
expect(target).to receive(:update_blocking_issues_count!)
create(:issue_link, target: target, source: source, link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
end
end
context 'with TYPE_RELATES_TO' do
it 'does not update blocking_issues_count' do
expect(source).not_to receive(:update_blocking_issues_count!)
......@@ -48,17 +39,6 @@ RSpec.describe IssueLink do
end
end
context 'with TYPE_IS_BLOCKED_BY' do
it 'updates blocking issues count' do
link = create(:issue_link, target: target, source: source, link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
expect(source).not_to receive(:update_blocking_issues_count!)
expect(target).to receive(:update_blocking_issues_count!)
link.destroy!
end
end
context 'with TYPE_RELATES_TO' do
it 'does not update blocking_issues_count' do
link = create(:issue_link, target: target, source: source, link_type: ::IssueLink::TYPE_RELATES_TO)
......@@ -75,12 +55,11 @@ RSpec.describe IssueLink do
describe '.blocked_issue_ids' do
it 'returns only ids of issues which are blocked' do
link1 = create(:issue_link, link_type: ::IssueLink::TYPE_BLOCKS)
link2 = create(:issue_link, link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
link3 = create(:issue_link, link_type: ::IssueLink::TYPE_RELATES_TO)
link4 = create(:issue_link, source: create(:issue, :closed), link_type: ::IssueLink::TYPE_BLOCKS)
link2 = create(:issue_link, link_type: ::IssueLink::TYPE_RELATES_TO)
link3 = create(:issue_link, source: create(:issue, :closed), link_type: ::IssueLink::TYPE_BLOCKS)
expect(described_class.blocked_issue_ids([link1.target_id, link2.source_id, link3.source_id, link4.target_id]))
.to match_array([link1.target_id, link2.source_id])
expect(described_class.blocked_issue_ids([link1.target_id, link2.source_id, link3.target_id]))
.to match_array([link1.target_id])
end
end
......@@ -90,7 +69,7 @@ RSpec.describe IssueLink do
blocking_issue = create(:issue, project: issue.project)
blocked_by_issue = create(:issue, project: issue.project)
create(:issue_link, source: blocking_issue, target: issue, link_type: ::IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue, target: blocked_by_issue, link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: blocked_by_issue, target: issue, link_type: ::IssueLink::TYPE_BLOCKS)
blocking_ids = described_class.blocking_issue_ids_for(issue)
......@@ -116,7 +95,7 @@ RSpec.describe IssueLink do
before :all do
create(:issue_link, source: blocking_issue_1, target: blocked_issue_1, link_type: ::IssueLink::TYPE_BLOCKS)
create(:issue_link, source: blocked_issue_2, target: blocking_issue_1, link_type: ::IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: blocking_issue_1, target: blocked_issue_2, link_type: ::IssueLink::TYPE_BLOCKS)
create(:issue_link, source: blocking_issue_2, target: blocked_issue_3, link_type: ::IssueLink::TYPE_BLOCKS)
end
......
......@@ -729,8 +729,8 @@ RSpec.describe Issue do
before_all do
create(:issue_link, source: blocking_issue, target: issue, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: other_project_blocking_issue, target: issue, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue, target: blocked_by_issue, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: issue, target: confidential_blocked_by_issue, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: blocked_by_issue, target: issue, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: confidential_blocked_by_issue, target: issue, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue, target: related_issue, link_type: IssueLink::TYPE_RELATES_TO)
create(:issue_link, source: closed_blocking_issue, target: issue, link_type: IssueLink::TYPE_BLOCKS)
end
......@@ -813,7 +813,7 @@ RSpec.describe Issue do
blocked_issue_2 = create(:issue, project: project)
blocked_issue_3 = create(:issue, project: project)
create(:issue_link, source: issue, target: blocked_issue_1, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: blocked_issue_2, target: issue, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: issue, target: blocked_issue_2, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue, target: blocked_issue_3, link_type: IssueLink::TYPE_BLOCKS)
# Set to 0 for proper testing, this is being set by IssueLink callbacks.
issue.update(blocking_issues_count: 0)
......
......@@ -54,7 +54,7 @@ RSpec.describe 'getting an issue list for a project' do
let_it_be(:blocking_issue2) { create(:issue, :confidential, project: project) }
let_it_be(:blocking_issue3) { create(:issue, project: project) }
let_it_be(:issue_link1) { create(:issue_link, source: blocked_issue1, target: blocking_issue1, link_type: 'is_blocked_by') }
let_it_be(:issue_link1) { create(:issue_link, source: blocking_issue1, target: blocked_issue1, link_type: 'blocks') }
let_it_be(:issue_link2) { create(:issue_link, source: blocking_issue2, target: blocked_issue2, link_type: 'blocks') }
let_it_be(:issue_link3) { create(:issue_link, source: blocking_issue3, target: blocked_issue2, link_type: 'blocks') }
......
......@@ -31,7 +31,7 @@ RSpec.describe Projects::IssuesController do
other_project_issue = create(:issue)
other_project_issue.project.add_developer(user)
create(:issue_link, source: issue, target: other_project_issue, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: other_project_issue, target: issue, link_type: IssueLink::TYPE_BLOCKS)
expect { get_show }.not_to exceed_query_limit(control)
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