Skip to content

Commit

Permalink
fix cache logic
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Jan 14, 2025
1 parent 86c1353 commit d9205a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/roled/ext/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Ext::Base
has_many :role_whos, class_name: 'Roled::RoleWho', as: :who
has_many :roles, class_name: 'Roled::Role', through: :role_whos

accepts_nested_attributes_for :role_whos
accepts_nested_attributes_for :role_whos, allow_destroy: true, reject_if: ->(attributes){ attributes.slice('role_id').blank? }

has_many :role_rules, class_name: 'Roled::RoleRule', through: :roles
has_many :tabs, class_name: 'Roled::Tab', through: :roles
Expand Down
6 changes: 3 additions & 3 deletions app/models/roled/model/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Model::Cache
attribute :str_role_ids, :string, index: true
attribute :role_hash, :json, default: {}

has_many :cache_roles
has_many :cache_roles, dependent: :delete_all
has_many :roles, through: :cache_roles

after_save :sync_role_caches, if: -> { saved_change_to_str_role_ids? }
Expand All @@ -18,8 +18,8 @@ def sync_role_caches
end

def reset_role_hash!
cache.role_hash = compute_role_hash
cache.save
self.role_hash = compute_role_hash
self.save
end

def compute_role_hash
Expand Down

0 comments on commit d9205a8

Please sign in to comment.