Difference between back-relation expand vs expanding using an explicitly set relation Id #3694
-
If I want to get an account with its balance and transactions then I can do either: // No transactionIds[] on 'accounts' and utilizing back relation expand
const response = await app.collection('accounts').getOne($page.params.accountId, {
expand: 'transactions(debit_account_id).debit_account_id,transactions(credit_account_id).credit_account_id'
}); OR // Explicitly set relation id's on both 'accounts' and 'transactions'
const response = await app.collection('accounts').getOne($page.params.accountId, {
expand: 'transactions.debit_account_id,transactions.credit_account_id'
});
return response; Is there any performance consideration here? I'm deciding if I should explicitly set relation ids server-side on |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I haven't benchmarked this particular case, but I don't expect the performance to differ that much because the back-relation expansion query execution is very similar to the direct relation expand (mainly there is an extra regex parsing on app level to separate the collection name and field). I'm not sure what to recommend as it would depend on how you want to structure your data, but personally I would go with whatever is more easy to work and maintain. I'm currently heavily using back-relation expand in one of my other projects (Presentator) where some of the relations are from large datasets with more than 200k-400k+ records and so far I haven't stumbled on anything to make me reconsider changing the data flow. |
Beta Was this translation helpful? Give feedback.
I haven't benchmarked this particular case, but I don't expect the performance to differ that much because the back-relation expansion query execution is very similar to the direct relation expand (mainly there is an extra regex parsing on app level to separate the collection name and field).
I'm not sure what to recommend as it would depend on how you want to structure your data, but personally I would go with whatever is more easy to work and maintain. I'm currently heavily using back-relation expand in one of my other projects (Presentator) where some of the relations are from large datasets with more than 200k-400k+ records and so far I haven't stumbled on anything to make me reconsid…