[LRUG] Advice: manipulating ActiveRecord objects [newbie]
Marco Iannone
marco.iannone at gmail.com
Tue Dec 15 04:37:21 PST 2015
This is great, many thanks everyone, much appreciated.
And sorry for the slow reply.
Duncan: re. swapping where and includes: .includes seems to prefer to
generate IN () style of SQL queries even in that case.
Frederick: we will try .eager_load and report back.
Combining the datasets yourself without using the .includes: that's the
issue, the responsebuilder does expect an activerecord object, so we'd need
to refactor that - what I alluded to as plan B. Definitely a possible
option. In fact, we'd create something else, as the responsebuilder is used
everywhere.
Julius: we'll definitely also add the .select, though it doesn't seem to
make a major difference, as the table has few columns.
Pagination: that's definitely a good idea, something we may need to add
anyway, also for usability.
Ed: that is the problem indeed: creating the hashes implies re-writing the
responsebuilder, which is our plan B if we can't figure out how to force
the right queries into the right activerecord object. Agreed on pagination.
[Incidentally, we didn't expect clients to have quite that many feeds. What
they say about real life messing up your plans etc.]
Graham: thanks, and interesting that there seems to be some consensus
around plan B.
Here are the gists of the responsebuilder
<https://gist.github.com/marcoi/c96fb66383147d096cf8>and feedbuilder
<https://gist.github.com/marcoi/f0202a8710700e924db2>(unnecessary stuff
removed). As I was mentioning the former is used everywhere, the latter
just here. We can build a bespoke builder.
Also: we found this, which may be helpful for plan A
http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html
Thanks again everyone, really appreciated. Let me know if anything comes to
mind, either way we'll report back once/if we get somewhere.
On 14 December 2015 at 14:50, Graham Ashton <graham at effectif.com> wrote:
> On Mon, 14 Dec 2015, at 02:23 PM, Ed Saunders wrote:
> >
> > I don't think the order of the "includes" or "where" will make a
> difference
> > though.
>
> Agreed.
>
> > Presumably either the FeedBuilder or ResponseBuilder is going to
> > call into the FeedDetail's associations which will make that difficult.
> > Without seeing those classes I'm not sure what else to suggest other
> than a
> > potential rewrite…
>
> This is what I was going to suggest, but I think we’d need to see what
> `ResponseBuilder` does to give you any actionable advice.
>
> My gut feeling is that if I was in your shoes I’d replace
> `ResponseBuilder` with templates (e.g. jbuilder), and pass the results of
> the three fast (and simple) queries to the templates via the render call.
> I’m not sure what the forces are on `ResponseBuilder` (e.g. how often is it
> used, and what else might it interact with?) though, so I wouldn’t call it
> a solid suggestion just yet…
>
> Could you share `ResponseBuilder` and `FeedBuilder` in a gist?
>
> --
> Graham Ashton (Founder, Agile Planner)
> https://www.agileplannerapp.com | @grahamashton | @agileplanner
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20151215/587ab18f/attachment-0002.html>
More information about the Chat
mailing list