Rather than cross joining each micronutrient to the list of food genuses and then searching for each one individually, the function now searches the FCT list for each food genus and then when it finds a match it collects the nutrient values for all outstanding micronutrients present in that FCT, keeping a list of what it hasn't yet found.
Execution now takes ~5mins, for the whole function, compared to the previous ~40mins 🚀
In testing the matched data returns a different number of rows than the previous algorithm (392,040 vs 451,440). This is because the updated function only matches on MNs in the micronutrient table where is_user_visible is true (N=33) rather than all MNs (N=38). However $(441440/38)*33=392040$
Probably addresses #303 - though there may be more perf improvements available 😁
Rather than cross joining each micronutrient to the list of food genuses and then searching for each one individually, the function now searches the FCT list for each food genus and then when it finds a match it collects the nutrient values for all outstanding micronutrients present in that FCT, keeping a list of what it hasn't yet found.
Execution now takes ~5mins, for the whole function, compared to the previous ~40mins 🚀
In testing the matched data returns a different number of rows than the previous algorithm (392,040 vs 451,440). This is because the updated function only matches on MNs in the micronutrient table where
is_user_visible
is true (N=33) rather than all MNs (N=38). However $(441440/38)*33=392040$Probably addresses #303 - though there may be more perf improvements available 😁