-
Notifications
You must be signed in to change notification settings - Fork 465
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
Implemented very simple caching to avoid unnecessary database queries #195
base: master
Are you sure you want to change the base?
Implemented very simple caching to avoid unnecessary database queries #195
Conversation
Not necessarily against project styles, but in general humans tend be better at seeing rather than reading. If you see :) |
I think this looks neat - but it makes me nervous. I wonder if there is a way to optionally add this, as I'm leaning away from merging this. |
Rails has a standard mechanism for storing relationships in an object. This is cleared out when calling a Also, with the introduction of rails 6.0, If we can turn it into a relationship, we gain a lot of great stuff. (like |
I'm currently trying to convert parent_id and ancestors as standard rails columns. I'm hoping that will lead us to being able to use standard associations (or slightly modified ones) |
I had some code which was calling
#parent
a lot. Rails:belongs_to
caches this to avoid hitting the database unnecessarily. After migrating to ancestry I noticed it was much slower because every call to#parent
resulted in the database being hit.This is obviously an incredibly naive / trivial cache and doesn't bother to even try to cache the more complex methods.
We could make it an opt in argument passed to
::has_ancestry
, but that seems really conservative.Any idea how to test this? Can we assert on number of queries run? Otherwise I'll write a test now asserting on the object equality, potentially through
#object_id
.