An insurer wants to determine how many activities have been generated to review a denial decision with an Account Manager. A developer has written this query:
uses gw.api.database.Query
var queryResults = Query.make(Activity).select().toCollection().where(
\ act -> act.ActivityPattern.Code == "account_denial" )
This query does not perform as well as it should. Where should the results be filtered to follow best practices?
In Guidewire InsuranceSuite, the performance of an application is heavily dependent on how efficiently it interacts with the database. The Gosu Query API is designed to allow developers to retrieve exactly the data they need by translating Gosu logic into optimized SQL statements.
The developer's current approach in the code snippet is a significant anti-pattern. By calling .select().toCollection(), the system executes a broad SQL query that retrieves every single record from the Activity table and loads them into the application server's memory (the 'Bundle'). Only after these potentially thousands of records are in memory does the .where() block filter them. This causes high memory consumption, increased network latency, and unnecessary pressure on the application server's garbage collector.
According to the Gosu Queries lesson in the InsuranceSuite Developer Fundamentals course, the best practice is to filter results In the database (Option D). This is achieved by using the compare() or join() methods on the Query object before calling .select(). For example, using query.compare(Activity#ActivityPattern, Equals, myPattern) ensures that the filtering is handled by the database engine via a SQL WHERE clause. Consequently, only the specific records that match the 'account_denial' criteria are sent over the network and loaded into memory. Following this practice minimizes the data 'payload,' reduces the execution time of the logic, and ensures the application remains scalable even as the volume of activities grows over time. Adhering to database-side filtering is a core requirement for passing Quality Gates in Guidewire Cloud environments.
==========
Currently there are no comments in this discussion, be the first to comment!