12 ms·
This really sounds like you're having an issue linked to the ORM. I don't know the Rails equivalent, but Django's ORM has a way of prefetching related fields o
by rtpg 10y ago
This really sounds like you're having an issue linked to the ORM.
I don't know the Rails equivalent, but Django's ORM has a way of prefetching related fields on a model in a single query.
My bet is that your code wasn't 1 query, but actually 4000 * 240 queries, which will always take a while.
EDIT: I just saw in a sibling comment that the actual data fetching was only taking 30s. I imagine you were doing that part mostly right