summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2017-05-10 23:54:10 +0300
committerValery Sizov <valery@gitlab.com>2017-05-12 14:12:29 +0300
commite2a3a5095abd8c1fa57dd19e4ff693ae4021fde8 (patch)
tree435cd38964d20a0b1ad67b9dc02dcdbbe76d00c1 /app
parent92bf7dfcb040e3e035fc87b0a70461f891284c98 (diff)
downloadgitlab-ce-e2a3a5095abd8c1fa57dd19e4ff693ae4021fde8.tar.gz
Move update_assignee_cache_counts to the service
Diffstat (limited to 'app')
-rw-r--r--app/models/issue_assignee.rb7
-rw-r--r--app/models/merge_request.rb8
-rw-r--r--app/models/user.rb5
-rw-r--r--app/services/issuable_base_service.rb6
-rw-r--r--app/services/members/authorized_destroy_service.rb3
5 files changed, 13 insertions, 16 deletions
diff --git a/app/models/issue_assignee.rb b/app/models/issue_assignee.rb
index 0663d3aaef8..06d760b6a89 100644
--- a/app/models/issue_assignee.rb
+++ b/app/models/issue_assignee.rb
@@ -3,11 +3,4 @@ class IssueAssignee < ActiveRecord::Base
belongs_to :issue
belongs_to :assignee, class_name: "User", foreign_key: :user_id
-
- after_create :update_assignee_cache_counts
- after_destroy :update_assignee_cache_counts
-
- def update_assignee_cache_counts
- assignee&.update_cache_counts
- end
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 59736f70f24..9e5db53b15e 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -125,7 +125,6 @@ class MergeRequest < ActiveRecord::Base
participant :assignee
after_save :keep_around_commit
- after_save :update_assignee_cache_counts, if: :assignee_id_changed?
def self.reference_prefix
'!'
@@ -187,13 +186,6 @@ class MergeRequest < ActiveRecord::Base
work_in_progress?(title) ? title : "WIP: #{title}"
end
- def update_assignee_cache_counts
- # make sure we flush the cache for both the old *and* new assignees(if they exist)
- previous_assignee = User.find_by_id(assignee_id_was) if assignee_id_was
- previous_assignee&.update_cache_counts
- assignee&.update_cache_counts
- end
-
# Returns a Hash of attributes to be used for Twitter card metadata
def card_attributes
{
diff --git a/app/models/user.rb b/app/models/user.rb
index f713a20233c..c7160a6af14 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -929,6 +929,11 @@ class User < ActiveRecord::Base
assigned_open_issues_count(force: true)
end
+ def invalidate_cache_counts
+ Rails.cache.delete(['users', id, 'assigned_open_merge_requests_count'])
+ Rails.cache.delete(['users', id, 'assigned_open_issues_count'])
+ end
+
def todos_done_count(force: false)
Rails.cache.fetch(['users', id, 'todos_done_count'], force: force) do
TodosFinder.new(self, state: :done).execute.count
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index c1e532b504a..dc2ab99b982 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -178,6 +178,7 @@ class IssuableBaseService < BaseService
after_create(issuable)
issuable.create_cross_references!(current_user)
execute_hooks(issuable)
+ issuable.assignees.each(&:invalidate_cache_counts)
end
issuable
@@ -234,6 +235,11 @@ class IssuableBaseService < BaseService
old_assignees: old_assignees
)
+ if old_assignees != issuable.assignees
+ assignees = old_assignees + issuable.assignees.to_a
+ assignees.compact.each(&:invalidate_cache_counts)
+ end
+
after_update(issuable)
issuable.create_new_cross_references!(current_user)
execute_hooks(issuable, 'update')
diff --git a/app/services/members/authorized_destroy_service.rb b/app/services/members/authorized_destroy_service.rb
index a85b9465c84..7912cac65d3 100644
--- a/app/services/members/authorized_destroy_service.rb
+++ b/app/services/members/authorized_destroy_service.rb
@@ -43,8 +43,9 @@ module Members
)
project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil)
- member.user.update_cache_counts
end
+
+ member.user.invalidate_cache_counts
end
end
end