Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster self_and_descendant_ids possible? #324

Open
peterwake opened this issue Sep 24, 2018 · 0 comments
Open

Faster self_and_descendant_ids possible? #324

peterwake opened this issue Sep 24, 2018 · 0 comments

Comments

@peterwake
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant