group relationship cache

This commit is contained in:
2458773093 2019-07-15 17:29:54 +03:00
parent fd0d9fc261
commit 3227e74ac6
2 changed files with 10 additions and 2 deletions

View File

@ -18,4 +18,12 @@ class GroupAccount < ApplicationRecord
belongs_to :account
validates :account_id, uniqueness: { scope: :group_id }
after_commit :remove_relationship_cache
private
def remove_relationship_cache
Rails.cache.delete("relationship:#{account_id}:group#{group_id}")
end
end

View File

@ -29,7 +29,7 @@ class GroupRelationshipsPresenter
@uncached_group_ids = []
@group_ids.each do |group_id|
maps_for_group = Rails.cache.read("relationship:#{@current_account_id}:#{group_id}")
maps_for_group = Rails.cache.read("relationship:#{@current_account_id}:group#{group_id}")
if maps_for_group.is_a?(Hash)
@cached.deep_merge!(maps_for_group)
@ -48,7 +48,7 @@ class GroupRelationshipsPresenter
admin: { group_id => admin[group_id] },
}
Rails.cache.write("relationship:#{@current_account_id}:#{group_id}", maps_for_account, expires_in: 1.day)
Rails.cache.write("relationship:#{@current_account_id}:group#{group_id}", maps_for_account, expires_in: 1.day)
end
end
end