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

Optimized query for filtering nodes with a given depth #17

Closed
bhavinkamani opened this issue Sep 3, 2012 · 4 comments
Closed

Optimized query for filtering nodes with a given depth #17

bhavinkamani opened this issue Sep 3, 2012 · 4 comments

Comments

@bhavinkamani
Copy link

What is the best way to get all the nodes with a given depth. Currently, I do Node.all.select {|n| n.depth == 3}. This generates one query for each iteration which isn't very optimized.

@mceachen
Copy link
Collaborator

mceachen commented Sep 3, 2012

You'd want a named scope so you can do it in one select. Do you think this
would be generally useful to add to the library?

Matthew

On Sep 3, 2012, at 3:30 AM, Bhavin notifications@github.com wrote:

What is the best way to get all the nodes with a given depth. Currently, I
do Node.all.select {|n| n.depth == 3}. This generates one query for each
iteration which isn't very optimized.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/17.

@bhavinkamani
Copy link
Author

Scope will do however having generic method such Tag.nodes(depth) will be cool.

I really liked this gem. I was also evaluating ltree Postgres Extension. I picked Closure Tree because it gives a more robust and SQL compliant non-proprietary approach and has super api. I also liked the fact that unlike ltree it retains the data integrity through foreign key association.

However, I do miss the querying ability of ltree. Would it make sense to use some of the ltree magic for postgres db behind the scene!!!

@mceachen
Copy link
Collaborator

mceachen commented Sep 4, 2012

This feature was released in version 3.5.0 just now. Search for find_all_by_generation in the readme.

@mceachen mceachen closed this as completed Sep 4, 2012
@bhavinkamani
Copy link
Author

That was really fast and very helpful :-). Thanks a lot for this beautiful gem.

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

2 participants