group member count optimization

This commit is contained in:
2458773093
2019-07-22 03:46:00 +03:00
parent bd3f453c0d
commit bf2d54201b
7 changed files with 45 additions and 5 deletions

View File

@@ -21,10 +21,20 @@ class GroupAccount < ApplicationRecord
validates :account_id, uniqueness: { scope: :group_id }
after_commit :remove_relationship_cache
after_create :increment_member_count
after_destroy :decrement_member_count
private
def remove_relationship_cache
Rails.cache.delete("relationship:#{account_id}:group#{group_id}")
end
def increment_member_count
group&.increment!(:member_count)
end
def decrement_member_count
group&.decrement!(:member_count)
end
end