diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/member.rb | 5 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 6 | ||||
-rw-r--r-- | app/models/user.rb | 36 |
3 files changed, 28 insertions, 19 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index 408e8b2d704..36090676051 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -85,6 +85,7 @@ class Member < ActiveRecord::Base after_create :create_notification_setting, unless: [:pending?, :importing?] after_create :post_create_hook, unless: [:pending?, :importing?] after_update :post_update_hook, unless: [:pending?, :importing?] + after_destroy :destroy_notification_setting after_destroy :post_destroy_hook, unless: :pending? after_commit :refresh_member_authorized_projects @@ -315,6 +316,10 @@ class Member < ActiveRecord::Base user.notification_settings.find_or_create_for(source) end + def destroy_notification_setting + notification_setting&.destroy + end + def notification_setting @notification_setting ||= user&.notification_settings_for(source) end diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index b6f1dd272cd..1c7ed4a96df 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -13,8 +13,6 @@ class ProjectMember < Member scope :in_project, ->(project) { where(source_id: project.id) } - before_destroy :delete_member_todos - class << self # Add users to projects with passed access option # @@ -93,10 +91,6 @@ class ProjectMember < Member private - def delete_member_todos - user.todos.where(project_id: source_id).destroy_all if user - end - def send_invite notification_service.invite_project_member(self, @raw_invite_token) diff --git a/app/models/user.rb b/app/models/user.rb index 9c60adf0c90..951b161203c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1035,14 +1035,33 @@ class User < ActiveRecord::Base end end + def todos_done_count(force: false) + Rails.cache.fetch(['users', id, 'todos_done_count'], force: force, expires_in: 20.minutes) do + TodosFinder.new(self, state: :done).execute.count + end + end + + def todos_pending_count(force: false) + Rails.cache.fetch(['users', id, 'todos_pending_count'], force: force, expires_in: 20.minutes) do + TodosFinder.new(self, state: :pending).execute.count + 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 + todos_done_count(force: true) + todos_pending_count(force: true) + end + def invalidate_cache_counts invalidate_issue_cache_counts invalidate_merge_request_cache_counts + invalidate_todos_done_count + invalidate_todos_pending_count end def invalidate_issue_cache_counts @@ -1053,21 +1072,12 @@ class User < ActiveRecord::Base Rails.cache.delete(['users', id, 'assigned_open_merge_requests_count']) end - def todos_done_count(force: false) - Rails.cache.fetch(['users', id, 'todos_done_count'], force: force, expires_in: 20.minutes) do - TodosFinder.new(self, state: :done).execute.count - end + def invalidate_todos_done_count + Rails.cache.delete(['users', id, 'todos_done_count']) end - def todos_pending_count(force: false) - Rails.cache.fetch(['users', id, 'todos_pending_count'], force: force, expires_in: 20.minutes) do - TodosFinder.new(self, state: :pending).execute.count - end - end - - def update_todos_count_cache - todos_done_count(force: true) - todos_pending_count(force: true) + def invalidate_todos_pending_count + Rails.cache.delete(['users', id, 'todos_pending_count']) end # This is copied from Devise::Models::Lockable#valid_for_authentication?, as our auth |