closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

Faster self_and_descendant_ids possible?

Open peterwake opened this issue 7 years ago • 0 comments

At the moment the method self_and_descendant_ids runs a pluck on the self_and_descendants method.

So we get SQL (for a model 'DirectoryEntry') as follows:

SELECT `directory_entries`.`id` FROM `directory_entries`
  INNER JOIN `directory_entry_hierarchies` ON 
   `directory_entries`.`id` = `directory_entry_hierarchies`.`descendant_id` WHERE 
  `directory_entry_hierarchies`.`ancestor_id` = 2 
  ORDER BY `directory_entry_hierarchies`.generations asc

Shouldn't it be possible to just change this logic to just use the [directory_entry_]hierarchies table to do something like:

SELECT `directory_entry_hierarchies`.`descendant_id` FROM `directory_entry_hierarchies`
 WHERE `directory_entry_hierarchies`.`ancestor_id` = 2

(not sure the ORDER BY is necessary?)

Please let me know what you think and I can write a PR.

peterwake avatar Sep 24 '18 07:09 peterwake