Preload associations scoped to current user

45 views
Skip to first unread message

Roman

unread,
Nov 19, 2014, 9:05:37 AM11/19/14
to rails-a...@googlegroups.com
There are Users, Things and Likes. User can like a Thing and Like is created.
When I serialize a list of Things, I need to provide a property in API for each Thing if it is liked by current User.
Doing this the straightforward way does not scale. What other variants do I have?
I believe this to be a common problem but can't find anyone solving it.

Thanks for your help

Roman

unread,
Nov 24, 2014, 6:22:00 AM11/24/14
to rails-a...@googlegroups.com
This place is dead :(

João Moura

unread,
Nov 24, 2014, 4:37:39 PM11/24/14
to rails-a...@googlegroups.com
Hi Roman, 

Sorry for take so long to reply. Indeed the list is a little bit empty, but it's because we are working hard to release new version of AMS. :)
Why you say it doesn't scale? Performance? 
Which version of AMS are you using it?
The first thing that come to my mind is compost cache. The Thing attributes would be cached but not the Liked flag. 
There are some ways of doing it, you may find it on google :) 
But I will try to address this kind of situation with a easier solution on the next version of AMS.

Best,

Roman

unread,
Nov 24, 2014, 6:27:44 PM11/24/14
to rails-a...@googlegroups.com
Hi João,

Thank you for response. I understand, everyone are not sitting here waiting for me to ask them something :)
By "doesn't scale" I mean, I would need to make a request to DB for each Thing to check if it's liked. It should be possible to get an aggregated Likes-data in a single query and pass it to the serializer.
I'm using latest 0.8 branch.
What do I google for? Compost cache? That's something I haven't heard of.

João Moura

unread,
Nov 25, 2014, 9:19:44 AM11/25/14
to rails-a...@googlegroups.com
Hey Roman,
Well, indeed the only way to retrieve this information would be checking if there is a relationship between Thing and User.
You can retrieve this kind of information with one single query if you want to but you would have to check how to send it properly to AMS.
I found a reference to what I was talking about, serializer composition, it's a great article.
Reply all
Reply to author
Forward
0 new messages