How do you folks retrieve all objects in code upfront?
I figure you can increase performance if you bundle all the model calls together?
This makes for a bigger deal, especially if your DB cannot keep everything in memory
def hitDBSeperately {
get X users
…codeget Y users… code
get Z users… code
}
Versus:
def hitDBInSingleCall {
get X+Y+Z users
code for X
code for Y…}
Are you looking for an explanation between the approach where you load in all users at once:
Where you could load them individually for a smaller memory footprint?
The second approach would be slower since it requires N+1 queries for N users, where the first loads them all with 1 query. However, you need to have sufficient memory for creating model instances for each and every User record at the same time. This is not a function of “DB memory”, but of application memory.
For any application with a non-trivial number of users, you should use an approach where you load users either individually or in groups. You can do this using:
By tuning to use an appropriate grouping factor, you can balance between memory usage and performance.