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

cache parent_id or root_id #354

Open
tilo opened this issue Jul 23, 2017 · 5 comments
Open

cache parent_id or root_id #354

tilo opened this issue Jul 23, 2017 · 5 comments

Comments

@tilo
Copy link
Contributor

tilo commented Jul 23, 2017

It would be nice to have Klass.is_parent as a scope

e.g. in a User model you often want to find all managers quickly

EDITED by kbrock:

This will allow us to fetch leafs and non-leaf nodes (discussion moved to #422)
It also cuts down a lot on processing if the parent_id is cached.
Caching in the database would be the best

@tilo
Copy link
Contributor Author

tilo commented Aug 24, 2017

@stefankroes bump..

@kbrock
Copy link
Collaborator

kbrock commented Aug 31, 2017

@tilo There are a few posts that talk about "leaves" that I think are similar to your request.

since the fact that this is a parent is not stored in the record itself, but the presence of other records, means this would be a query with an exists clause.

Have you come up with a query that meets your needs?

@KevinColemanInc
Copy link

I can jump in here as I worked with tilo on this problem.

We ended up doing this adding a separate parent id column. For our purposes, it made simple queries for:

  1. Finding everyone that is a parent
  2. Joining against the parent
  before_save :sync_parent_id_from_ancestry, if: :ancestry_changed?

  def sync_read_only_parent_id_from_ancestry
    write_attribute(:read_only_parent_id, self.parent_id)
  end

@kbrock
Copy link
Collaborator

kbrock commented Mar 19, 2019

I think the solution is to revamp the nodes like suggested in #422 - we need to start using sql instead of the darned to_node junk

@kbrock
Copy link
Collaborator

kbrock commented Mar 18, 2023

@KevinColemanInc This is very old...

I'm leaving the asking for leafs / parents over in #422

I'm taking liberty for the definition of this feature request as caching parent_id
there is a lot of stuff you could get from there

@kbrock kbrock changed the title scope has_children / is_parent cache parent_id or root_id Mar 18, 2023
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

3 participants