Reposting this, because I failed to reply to post, and replied to author 
instead accidentally.

On Monday, December 2, 2013 9:33:03 PM UTC-6, Jeremy Evans wrote:

> You could try switching to an after_load hook on the association instead 
> of after_initialize hook on the model.
>

Thank you!  I completely failed to find that in the docs.  I'm sure it's 
there, and I just missed it.  It is exactly ideal, and it works perfectly.


I think the after_load hook should fix this, since it should only be run 
> once.
>

Perfect.


Unfortunately, I cannot seem to reliably get rcte tree model instances to 
>> keep themselves in a global in-memory cache (let alone a memcached 
>> instance), and from it be subsequently retrieved.  It seems that only some 
>> instances are loaded into the cache, and then only the main model instance, 
>> with none of its associations.
>>
>
> Well, for the children association, this is expected, since Sequel doesn't 
> support a cache lookup for one_to_many associations.  For the parent 
> association, it should use a cache lookup if you are using the caching 
> plugin.
>

Interesting, I did not know this.  However, what I meant was, that only the 
main model instance seems to get loaded into cache, and none of its 
non-rcte tree associations -- that is, ideally I would prefer that the 
non-child many-to-many associations get automatically loaded along with the 
model instance.

use Dataset#eager on the dataset that creates the objects, or the 
> tactical_eager_loading plugin, in conjuction with Dataset#all to load the 
> objects.
>

Is it possible to do this automatically? [*] That is, upon retrieving the 
children of a node, and dealing with an individual instance within that 
set, is it possible to specify that all of that node instance's normal 
many-to-many association members (non-rcte tree associations) get 
implicitly included in the query which fetches those children?

 

> The query you post does not make sense in rcte_tree context, since it 
> appears to be using a join table, and the rcte_tree plugin does not.
>

Yes.  So, Artists could be considered to be nodes in the tree, and albums 
are normal non-hierarchical many-to-many associations, joined through an 
artist_to_album table and entity.

 

>  
>
>> I think that I understand that this may not be possible in conjunction 
>> with the rcte_tree plugin for Sequel.  For some reason I was under the 
>> impression that association eager loading was working for normal 
>> associations, just not for the tree associations.  (Perhaps until recently?)
>>
>
> The only thing the rcte_tree plugin gives you is that it allows you do get 
> all ancestors or descendents (or descendents to some level) in a single 
> query.  You so far have not described usage of those features, so you are 
> probably just using the associations added by the tree plugin (which the 
> rcte_tree plugin loads).
>

I do use ancestors and descendants elsewhere in the program, but there is 
one spot in the program where a given node's branch is programmatically 
pre-order traversed, and information retrieved.  I may have to rework this, 
because it is bit of a performance pain point for the application.

However, the associations with which I am concerned are not the children 
associations.  They are just the normal many-to-many associations on the 
individual nodes.


The caching plugin should only affect the parent lookup, not the children 
> lookup.  The tactical_eager_loading plugin should affect things, but it 
> requires that you use Dataset#all to retrieve the objects originally.
>

I am worried that this answers my question above. [*]


I don't have much experience with Neo4j, so I can't say whether it would be 
> a better choice or not.  However, I think PostgreSQL and Sequel should be 
> able to do what you need.
>

I (want to) think that you are correct.  I don't have much experience with 
Neo4j either, I was just hoping to see if someone in the forum might have 
any opinions on its suitability, in context with PostgreSQL and tree 
conventions.


Hopefully the above has been helpful in some way.
>

Absolutely it has.  The after_load method has reduced programmatic time for 
certain often-used routines by about 30%.

 

> If you have additional questions, it would be a good idea to post simple 
> self-contained example code that isn't working the way you want, and ask 
> how to do what you want in the context of the example.
>

I'll continue to work on that.  You're always incredibly helpful, Jeremy. 
 I don't know how you find the time!

Thanks again,
-Nels

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to