details:   https://code.openbravo.com/erp/devel/pi/rev/c35e5b050f0b
changeset: 29892:c35e5b050f0b
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Wed Aug 24 11:54:52 2016 +0200
summary:   Fixed 33790. Avoid double query with .count() + .list(). Add limit 1 
to query

Query did .count() + then retrieve 1 record after adding extra order by.

This change removes the count as it only adds extra overhead and directly
does the real .list() query.
As the code only uses single row of result add extra limit 1 to reduce
number of result rows loaded into memory if many match the filter.
Simply code to use .uniqueResult() instead of .list().get(0)

diffstat:

 src/org/openbravo/erpCommon/info/PriceListVersionFilterExpressionName.java |  
8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diffs (18 lines):

diff -r 3d8d5b58f0ec -r c35e5b050f0b 
src/org/openbravo/erpCommon/info/PriceListVersionFilterExpressionName.java
--- 
a/src/org/openbravo/erpCommon/info/PriceListVersionFilterExpressionName.java    
    Wed Aug 24 11:08:58 2016 +0200
+++ 
b/src/org/openbravo/erpCommon/info/PriceListVersionFilterExpressionName.java    
    Wed Aug 24 11:54:52 2016 +0200
@@ -127,11 +127,9 @@
         PriceListVersion.class);
     plVersionCrit.add(Restrictions.eq(PriceListVersion.PROPERTY_PRICELIST, 
priceList));
     plVersionCrit.add(Restrictions.le(PriceListVersion.PROPERTY_VALIDFROMDATE, 
date));
-    if (plVersionCrit.count() > 0) {
-      plVersionCrit.addOrderBy(PriceListVersion.PROPERTY_VALIDFROMDATE, false);
-      return plVersionCrit.list().get(0);
-    }
-    return null;
+    plVersionCrit.addOrderBy(PriceListVersion.PROPERTY_VALIDFROMDATE, false);
+    plVersionCrit.setMaxResults(1);
+    return (PriceListVersion) plVersionCrit.uniqueResult();
   }
 
   private boolean isSalesTransaction() {

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to