2 ms·
The N+1 problem was fixed by changing the ViewModel to use a left join which pulled all the records in one query. This is a classic ORM problem. The usual sol
by stcredzero 16y ago
The N+1 problem was fixed by changing the ViewModel to use a left join which pulled all the records in one query.
This is a classic ORM problem. The usual solution: apply a Declarative Batch Query. I've even written one of those things! The reason why you might want to code a Declarative Batch Query option for your Object Relational framework? You can then apply it to similar problem queries in a few minutes total and one line of code.
The first operation I optimized went from 2500 SQL calls to just 40, which is an over 50X speedup. And yes, the entire declarative mechanism was written in about a week to satisfy a routine "Change Request," and yes, it ran in production on a heavily used trading application at a major multinational.