0
@@ -124,7 +124,7 @@ module ActsAsCached
0
pkey_name = reflection.primary_key_name
0
- reflection.klass.
before_save do |instance|
0
+ reflection.klass.
after_save do |instance|
0
if instance.changes[pkey_name]
0
# Need to add id to parent's cache list ONLY if parent had the id list in cache in the first place
0
key = "#{instance.send(pkey_name)}:#{ids_reflection}"
0
@@ -153,22 +153,20 @@ module ActsAsCached
0
skey_name = reflection.options[:through] ? reflection.source_reflection.primary_key_name : :id
0
r = reflection.options[:through] ? reflection.through_reflection : reflection
0
- r.klass.
before_save do |instance|
0
+ r.klass.
after_save do |instance|
0
# if the foreign_key on self was changed
0
if instance.changes[pkey_name]
0
# Need to add id to parent's cache list ONLY if parent had the id list in cache in the first place
0
key = "#{instance.send(pkey_name)}:#{ids_reflection}"
0
- if reflection.active_record.cached?(key)
0
- assoc_ids = reflection.active_record.fetch_cache(key)
0
+ unless (assoc_ids = reflection.active_record.fetch_cache(key)).nil?
0
assoc_ids << instance.send(skey_name)
0
reflection.active_record.set_cache(key, assoc_ids.uniq)
0
# if we are doing an update of the foreign_key rather than an insert, make sure we remove ourselves from our old parent's cache
0
key = "#{instance.changes[pkey_name].first}:#{ids_reflection}"
0
- unless instance.changes[pkey_name].first.nil? || !reflection.active_record.cached?(key)
0
- assoc_ids = reflection.active_record.fetch_cache(key)
0
+ unless instance.changes[pkey_name].first.nil? || (assoc_ids = reflection.active_record.fetch_cache(key)).nil?
0
assoc_ids.delete(instance.send(skey_name))
0
reflection.active_record.set_cache(key, assoc_ids.uniq)
0
@@ -178,8 +176,7 @@ module ActsAsCached
0
# If an obj is destroyed, update the parent's cached id list
0
r.klass.after_destroy do |instance|
0
key = "#{instance.send(pkey_name)}:#{ids_reflection}"
0
- if reflection.active_record.cached?(key)
0
- assoc_ids = reflection.active_record.fetch_cache(key)
0
+ unless (assoc_ids = reflection.active_record.fetch_cache(key)).nil?
0
assoc_ids.delete(instance.send(skey_name))
0
reflection.active_record.set_cache(key, assoc_ids.uniq)
Comments
No one has commented yet.