From 3227e74ac6eb81a0308636de8b787745aafbaed5 Mon Sep 17 00:00:00 2001 From: 2458773093 <2458773093@protonmail.com> Date: Mon, 15 Jul 2019 17:29:54 +0300 Subject: [PATCH] group relationship cache --- app/models/group_account.rb | 8 ++++++++ app/presenters/group_relationships_presenter.rb | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/group_account.rb b/app/models/group_account.rb index 95533100..ea4ec62d 100644 --- a/app/models/group_account.rb +++ b/app/models/group_account.rb @@ -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 diff --git a/app/presenters/group_relationships_presenter.rb b/app/presenters/group_relationships_presenter.rb index b77d6511..72688cd2 100644 --- a/app/presenters/group_relationships_presenter.rb +++ b/app/presenters/group_relationships_presenter.rb @@ -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