Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0033767Openbravo ERPA. Platformpublic2016-08-23 14:432016-12-19 12:17
shuehner 
platform 
normalminorhave not tried
closedfixed 
5
 
3.0PR17Q1 
caristu
Core
No
0033767: Add code to auto-detect 'accidental double query' on same OBQuery or OBCriteria object
There is a quite common bad coding pattern which calls '.list()' more than one time on the same OBCriteria or OBQuery object.

That will call the underlying sql query also 2 times.

Similar some code without good reason calls .count() + then .list() on the same instance. Which leads to a 'select count(*)' + then another 'select *' sql query.

Detecting such pattern is easy with some extra debugging code inside those 2 utility classes.

See attached patch for a rough patch doing some simple tracking.

Not polished yet but did already find 6 issues in fast manual testing + more 'to be triaged' when running erp-try with it applied.

The attached patch logs a WARN + a stacktrace of the location of and 2nd or 3rd call to either list,count,scroll.uniqueResult.

In practice that 2nd location is enough as a pointer and finding the first call in code is very easy in all examples observed so far.
https://issues.openbravo.com/view.php?id=33703 [^]
https://issues.openbravo.com/view.php?id=33704 [^]
https://issues.openbravo.com/view.php?id=33705 [^]
https://issues.openbravo.com/view.php?id=33706 [^]
https://issues.openbravo.com/view.php?id=33707 [^]
https://issues.openbravo.com/view.php?id=33709 [^]
Performance
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 
related to defect 0033709 closed shuehner Retail Modules Double query for posterminal in POSUtil.getLastDocumentNumber*ForPos 
related to defect 0033769 closed shuehner Openbravo ERP ModuleManagement Settings page load trigger accidental double query to ad_ref_list 
related to defect 0033770 acknowledged Triage Platform Base Openbravo ERP ModuleManagement install from local obx triggers accidental 4* load of ad_module_dependency 
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 defect 0033816 closed caristu Openbravo ERP Find a complete solution to protect OBCriteria.initialize() against multiple calls per instance 
related to defect 0033772 closed shuehner Openbravo ERP Accidental double query in SelectorDefaultFilterActionHandler 
related to defect 0033789 closed shuehner Openbravo ERP Accidental double queries in org.openbravo.services.db.CallProcess 
related to defect 0033790 closed shuehner Openbravo ERP Accidental double query in PriceListVersionFilterExpressionName (order lines, product selector dropdown) 
related to defect 0033794 closed shuehner Openbravo ERP Accidental double queries in DataSourceServiceProvider.getDataSourceFromDataSourceName 
related to defect 0033158 closed shuehner Retail Modules Duplicate query done by accident in OrderLoader.createShipmentLines 
related to feature request 0034770 acknowledged Triage Platform Base Openbravo ERP Add code to auto-detect 'accidental double query' on same OBQuery object 
related to design defect 0036898 new Triage Finance Openbravo ERP Performance issues when using DAL 
diff 33767_prototype.diff (4,677) 2016-08-23 14:44
https://issues.openbravo.com/file_download.php?file_id=9745&type=bug
Issue History
2016-08-23 14:43shuehnerNew Issue
2016-08-23 14:43shuehnerAssigned To => platform
2016-08-23 14:43shuehnerModules => Core
2016-08-23 14:43shuehnerTriggers an Emergency Pack => No
2016-08-23 14:43shuehnerTag Attached: Performance
2016-08-23 14:44shuehnerFile Added: 33767_prototype.diff
2016-08-23 14:44shuehnerRelationship addedrelated to 0033703
2016-08-23 14:44shuehnerRelationship addedrelated to 0033704
2016-08-23 14:44shuehnerRelationship addedrelated to 0033705
2016-08-23 14:44shuehnerRelationship addedrelated to 0033706
2016-08-23 14:44shuehnerRelationship addedrelated to 0033707
2016-08-23 14:45shuehnerRelationship addedrelated to 0033709
2016-08-23 16:37shuehnerRelationship addedrelated to 0033769
2016-08-23 17:03shuehnerRelationship addedrelated to 0033770
2016-08-23 17:14shuehnerRelationship addedrelated to 0033771
2016-08-23 17:20shuehnerRelationship addedrelated to 0033772
2016-08-23 17:33shuehnerRelationship addedrelated to 0033773
2016-08-23 17:57shuehnerRelationship addedrelated to 0033774
2016-08-24 11:04shuehnerRelationship addedrelated to 0033789
2016-08-24 11:41shuehnerRelationship addedrelated to 0033790
2016-08-24 14:21shuehnerRelationship addedrelated to 0033794
2016-08-24 15:01shuehnerRelationship addedrelated to 0033158
2016-12-19 10:21caristuRelationship addedrelated to 0033816
2016-12-19 10:49caristuNote Added: 0092758
2016-12-19 10:51caristuNote Edited: 0092758bug_revision_view_page.php?bugnote_id=0092758#r14047
2016-12-19 10:52caristuNote Edited: 0092758bug_revision_view_page.php?bugnote_id=0092758#r14048
2016-12-19 12:10caristuIssue cloned0034770
2016-12-19 12:10caristuRelationship addedrelated to 0034770
2016-12-19 12:17caristuReview Assigned To => caristu
2016-12-19 12:17caristuNote Added: 0092772
2016-12-19 12:17caristuStatusnew => closed
2016-12-19 12:17caristuResolutionopen => fixed
2016-12-19 12:17caristuFixed in Version => 3.0PR17Q1
2017-09-19 18:48markmm82Relationship addedrelated to 0036898

Notes
(0092758)
caristu   
2016-12-19 10:49   
(edited on: 2016-12-19 10:52)
Accidental double query in OBCriteria is now detected with the fix for issue 0033816. It will be detected because the initialized method of the OBCriteria instance will be invoked twice, and in that case a warning is displayed in the log.

(0092772)
caristu   
2016-12-19 12:17   
Fixed for OBCriteria with the fix for issue 0033816.

A new issue for OBQuery class has been created: 0034770.