Open
Description
For an AR model VirtualPath
used for a DB based file system, we use this excellent gem.
When loading a bunch of the models after applying access control and other restrictions, we build up the hierarchy for a recursive "ls" style output and use ancestry_path
for the parts.
To speed up loading the ancestors, we try to use eager loading:
However, this mixes up the order of the ancestry path elements.
Example queries and output:
irb(main):063:0> VirtualPath.limit(4).map(&:ancestry_path)
=> [["Root"], ["Root", "FunnyFolder-1"], ["Root", "FunnyFolder-2"], ["Root", "FunnyFolder-2", "Funny-Sub-2"]]
irb(main):064:0> VirtualPath.limit(4).eager_load(:self_and_ancestors).map(&:ancestry_path)
=> [["Root"], ["FunnyFolder-1", "Root"], ["FunnyFolder-2", "Root"], ["Funny-Sub-2", "FunnyFolder-2", "Root"]]
Any solutions to this? Other users seem to cache the ancestry_path for speeding up this use case..
Can't this be done with AR queries only?
Metadata
Metadata
Assignees
Labels
No labels