This code sample performs poorly due to the use of dot notation with multiple array expansions: var lineItems = Claim.Exposures*.Transactions*.LineItems. What is the recommended best practice to improve the performance of this code?
Show answerHide answer
Correct answer: D Replace the dot notation syntax in the code with ArrayLoader syntax
Explanation
Answer Option (Which option is correct) D. Replace the dot notation syntax in the code with ArrayLoader syntaxExplanation:
Expanding multiple entity arrays can materialize many intermediate objects and trigger additional database reads. Review the relationship traversal and use a deliberate iteration or database-query strategy suited to the data volume. The supplied answer key is retained where the source chooses a particular traversal strategy.
Verification note: The source selects ArrayLoader for multiple array expansion but does not define the required API or implementation. Its relationship to the traversal advice in Q22 and Q138 needs review.
Why the other options are incorrect:
A. Rewrite the code with a nested for loop to retrieve the results:
Nested iteration can avoid intermediate expansion arrays. It may be a reasonable alternative for some relationship paths. The source supplies no evidence excluding it in favor of ArrayLoader.
B. Break the code into multiple gosu queries to retrieve the results for each array:
Separate queries may reduce unnecessary entity traversal. Their efficiency depends on their predicates and joins. The question does not specify enough implementation detail to reject this approach confidently.
C. Write a query that fetches the addresses into a collection then uses where() to filter the results:
The proposed query concerns addresses rather than line items. It also filters a retrieved collection with where. That does not directly solve the displayed line-item traversal.
References:
Gosu language project - Operators, loops, functions, and properties
Guidewire - Query-backed collections and buildBaseQuery