The heart of my app is a multi-conditional comparison using an input array and parameters stored in a few database tables.
I'm trying to make the process most efficient ... and I think this could lead to some good conversation about using memory vs. accessing a database.
Here's one example:
- I have a
Merchant
,MerchantUserRelation
, andUser
table. - Most of the data I need to store in a temporary array is from
MerchantUserRelation
, BUT at one point, I need to check if it's the user's birthday (user.birthdate.today?
).
To me, it seems there are two options:
- Create a temporary array with only data from
UserMerchantRelation
and then access the database separately for theuser.birthdate.today?
method (2 hits to the database), --or-- - Create a slightly-larger temporary array with both the data from
UserMerchantRelation
ANDUser
(and thus hit the database only once)
For this example I recognize the differences are EXTREMELY small (read: negligible), but what if the array sizes and # of database accesses required were much larger?
Thank you for any references and/or insights!