closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

Passing touch along to ancestors instead of descendants (for cache expiry of nested content)?

Open nruth opened this issue 8 years ago • 2 comments

:touch delegates to the belongs_to annotation for the parent, so touching cascades to all children (the performance of this for deep trees isn't currently optimal).

So, when a parent is updated it passes on the timestamp change to its children (descendants?).

I'd like the reverse behaviour, with an updated child passing its timestamp changes up to all of its ancestors. Something like this:

after_save :touch_ancestors_for_cache_expiry

def touch_ancestors_for_cache_expiry
  ancestors.to_a.each(&:touch)
end

Would it make sense to support both of these in the has_closure_tree call?

nruth avatar Feb 20 '17 10:02 nruth

I haven't needed this, but if you want to build it (please include tests!), I'm welcome to a PR!

mceachen avatar Mar 02 '17 16:03 mceachen

This is certainly something which I'd like to see myself. @nruth did you ever make any progress on this? My guess is that one concern might be around creating an infinite loop?

i.e. A descendant touches its parent, which touches its descendant, which touch parent etc etc...

In my given use case, I'd ideally like an object to touch all associated descendants and ancestors - how viable that is I'm not sure.

SirRawlins avatar May 09 '17 09:05 SirRawlins