Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0036898Openbravo ERPI. Performancepublic2017-09-19 18:432017-09-19 18:56
markmm82 
Triage Finance 
normalminoralways
newopen 
5
 
 
Core
No
0036898: Performance issues when using DAL
On many occasions when we perform a query with DAL, we do not do it quite well from a performance point of view. Here are some rules we should always follow:
• When we just want to know the number of records returned by the query, we usually do: query.list().size(). However it is better to do query.count(). If in addition to the number of records, we want to go through them, then it is better to store in a variable the result: list = query.list() and then look at its size: list.size().
• If, in addition to scrolling through the list, we want to know if we have at least one record, what we should do is: list.isEmpty(), instead of list.size ()> 0.
• It is important not to ever run the query.list() more than once, since that throws the same query twice. To do this, we execute the query only once and store it in a variable.
• When we only want to access the first record returned by the query, then we must use query.setMaxResults(1) in case the query returns more than one record, and we will return it using object = query.uniqueResult() instead of doing query.list().get(0).
• If you want to see if the query returns a record or not, just do the previous point and see if object ! = null.

These issues are found in many places along OB. For each of these cases code should be adapted to behave as explained above.
-
Performance
related to defect 0033771 closed shuehner Openbravo ERP Accidental double query in SE_Invoice_BPartner.isAutomaticCombination 
related to defect 0033773 closed shuehner Openbravo ERP Accidental double queries in Initial Client Setup 
related to defect 0033774 closed shuehner Openbravo ERP Accidental double queries in Initial Org Setup 
related to feature request 0033767 closed platform Openbravo ERP Add code to auto-detect 'accidental double query' on same OBQuery or OBCriteria object 
related to defect 0033703 closed shuehner Openbravo ERP Accidental double query in View generation 
related to defect 0033704 closed shuehner Openbravo ERP Accidental double query in 'selector dropdown' of new style selectors 
related to defect 0033705 closed shuehner Openbravo ERP Double query in PricelistVersionFilterExpression (product selector) 
related to defect 0033706 closed shuehner Openbravo ERP SelectorDataSourceFilter does accidental extra queries in 'Add Payment' flow of Sales Orders 
related to defect 0033707 closed shuehner Openbravo ERP Accidental triple query in OBMessageUtils.getI18NMessage 
depends on defect 0033709 closed shuehner Retail Modules Double query for posterminal in POSUtil.getLastDocumentNumber*ForPos 
related to defect 0036747 closed AtulOpenbravo Openbravo ERP Avoid query more than once in several classes 
diff 0.diff (14,677) 2017-09-19 18:52
https://issues.openbravo.com/file_download.php?file_id=11078&type=bug
txt 0.txt (962) 2017-09-19 18:53
https://issues.openbravo.com/file_download.php?file_id=11079&type=bug
Issue History
2017-09-19 18:43markmm82New Issue
2017-09-19 18:43markmm82Assigned To => Triage Finance
2017-09-19 18:43markmm82Modules => Core
2017-09-19 18:43markmm82Triggers an Emergency Pack => No
2017-09-19 18:47markmm82Relationship addedrelated to 0033771
2017-09-19 18:47markmm82Relationship addedrelated to 0033773
2017-09-19 18:47markmm82Relationship addedrelated to 0033774
2017-09-19 18:48markmm82Relationship addedrelated to 0033767
2017-09-19 18:48markmm82Relationship addedrelated to 0033703
2017-09-19 18:49markmm82Relationship addedrelated to 0033704
2017-09-19 18:49markmm82Relationship addedrelated to 0033705
2017-09-19 18:49markmm82Relationship addedrelated to 0033706
2017-09-19 18:50markmm82Relationship addedrelated to 0033707
2017-09-19 18:50markmm82Relationship addeddepends on 0033709
2017-09-19 18:51markmm82Tag Attached: Performance
2017-09-19 18:52markmm82File Added: 0.diff
2017-09-19 18:53markmm82File Added: 0.txt
2017-09-20 13:09aferrazRelationship addedrelated to 0036747

There are no notes attached to this issue.