Model-driven apps are highly customized and can pull data from many different sources to satisfy your business needs. When using custom logic to retrieve data from CDS or any other data source, one important factor to consider is – performance. Typically, pro developers use JavaScript to request data using Web API calls like retrieve Entity using the fetch query filters.
These query can be expensive if filters are not applied judiciously and may become expensive. Consider a case where customer wants to ensure if at least one record exists matching the requirement, the retrieve calls can be crafted just to retrieve the top record. The addition of retrieving only top record saves lot of work for the server, as this will stop the scan after fetching the record. This also play a significant role in page load times, in case if there's more than one record in the results for the query is not ordered by any condition.
For example, In the below code snippet , the user is trying to retrieve all the records associated with a particular entity and after the results are retrieved, user checks if at least one record exists and accesses only the first record. This can be easily replaced by retrieving only the top record and access the retrieved record.
Read more...