diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-05-12 15:37:18 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-05-19 11:41:24 +0300 |
commit | f0c0bdc047aa050698bebd30a7790eebe460d031 (patch) | |
tree | e1dae1c3af0d33619878caddff792ac58633eb2f /app | |
parent | aa7f474c4de8c7c183101b88d8e128abeffbe2bf (diff) |
Merge branch 'update_assignee_cache_counts_refactoring' into 'master'
Rework update_assignee_cache_counts
Closes #31873
See merge request !11270
Diffstat (limited to 'app')
-rw-r--r-- | app/models/issue_assignee.rb | 7 | ||||
-rw-r--r-- | app/models/merge_request.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 5 | ||||
-rw-r--r-- | app/services/issuable_base_service.rb | 6 | ||||
-rw-r--r-- | app/services/members/authorized_destroy_service.rb | 3 |
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 e88a86ea0f0..e13e795dbed 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -123,7 +123,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 '!' @@ -185,13 +184,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 3228081a999..ad24ec0ec08 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -919,6 +919,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 6e987b3b6cd..f846d72498f 100644 --- a/app/services/members/authorized_destroy_service.rb +++ b/app/services/members/authorized_destroy_service.rb @@ -52,8 +52,9 @@ module Members delete_all 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 |