Commit 20e9b32c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ui-mr-counter-cache' into 'master'

Deleting a MR you are assigned to should decrements counter

Closes #44458

See merge request gitlab-org/gitlab-ce!17951
parents 6cad7343 b099c6ff
...@@ -1046,11 +1046,6 @@ class User < ActiveRecord::Base ...@@ -1046,11 +1046,6 @@ class User < ActiveRecord::Base
end end
end end
def update_cache_counts
assigned_open_merge_requests_count(force: true)
assigned_open_issues_count(force: true)
end
def update_todos_count_cache def update_todos_count_cache
todos_done_count(force: true) todos_done_count(force: true)
todos_pending_count(force: true) todos_pending_count(force: true)
......
...@@ -4,6 +4,7 @@ module Issuable ...@@ -4,6 +4,7 @@ module Issuable
TodoService.new.destroy_target(issuable) do |issuable| TodoService.new.destroy_target(issuable) do |issuable|
if issuable.destroy if issuable.destroy
issuable.update_project_counter_caches issuable.update_project_counter_caches
issuable.assignees.each(&:invalidate_cache_counts)
end end
end end
end end
......
---
title: Deleting a MR you are assigned to should decrements counter
merge_request: 17951
author: m b
type: fixed
...@@ -8,7 +8,7 @@ describe Issuable::DestroyService do ...@@ -8,7 +8,7 @@ describe Issuable::DestroyService do
describe '#execute' do describe '#execute' do
context 'when issuable is an issue' do context 'when issuable is an issue' do
let!(:issue) { create(:issue, project: project, author: user) } let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
it 'destroys the issue' do it 'destroys the issue' do
expect { service.execute(issue) }.to change { project.issues.count }.by(-1) expect { service.execute(issue) }.to change { project.issues.count }.by(-1)
...@@ -26,10 +26,15 @@ describe Issuable::DestroyService do ...@@ -26,10 +26,15 @@ describe Issuable::DestroyService do
expect { service.execute(issue) } expect { service.execute(issue) }
.to change { user.todos_pending_count }.from(1).to(0) .to change { user.todos_pending_count }.from(1).to(0)
end end
it 'invalidates the issues count cache for the assignees' do
expect_any_instance_of(User).to receive(:invalidate_cache_counts).once
service.execute(issue)
end
end end
context 'when issuable is a merge request' do context 'when issuable is a merge request' do
let!(:merge_request) { create(:merge_request, target_project: project, source_project: project, author: user) } let!(:merge_request) { create(:merge_request, target_project: project, source_project: project, author: user, assignee: user) }
it 'destroys the merge request' do it 'destroys the merge request' do
expect { service.execute(merge_request) }.to change { project.merge_requests.count }.by(-1) expect { service.execute(merge_request) }.to change { project.merge_requests.count }.by(-1)
...@@ -41,6 +46,11 @@ describe Issuable::DestroyService do ...@@ -41,6 +46,11 @@ describe Issuable::DestroyService do
service.execute(merge_request) service.execute(merge_request)
end end
it 'invalidates the merge request caches for the MR assignee' do
expect_any_instance_of(User).to receive(:invalidate_cache_counts).once
service.execute(merge_request)
end
it 'updates the todo caches for users with todos on the merge request' do it 'updates the todo caches for users with todos on the merge request' do
create(:todo, target: merge_request, user: user, author: user, project: project) create(:todo, target: merge_request, user: user, author: user, project: project)
......
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