Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0027170Openbravo ERPA. Platformpublic2014-07-23 20:342015-05-19 01:33
jecharri 
eduardo_Argal 
urgentmajoralways
closedfixed 
5
 
3.0PR15Q3 
eduardo_Argal
Google Chrome
Core
No
0027170: Problem in event handler CharacteristicValueEventHandler.java when you update a characteristics value
Problem in event handler CharacteristicValueEventHandler.java when you update a characteristics value
-In a database with a los of product using product characteristics.Tab "characteristics" inside window "Product"
-Login to ERP
-Go to "product characteristics" window and select one.
-Go to tab "Value" and after selecting a record, modify the code or insert a new one

You will see that JAVA starts taking all the memory and the server stops working.

The problem is eventhandler CharacteristicValueEventHandler.java because we are doing
if (productCharateristic.count() > 0) {
             for (ProductCharacteristic productch : productCharateristic.list()) {
and
 for (ProductCharacteristicConf conf : productCharateristicsConf.list()) {
instead of using ScrollableResults.




  public void onUpdate(@Observes EntityUpdateEvent event) {
    if (!isValidEvent(event)) {
      return;
    }
    final CharacteristicValue chv = (CharacteristicValue) event.getTargetInstance();
    chvalueUpdated.set(chv.getId());
    // Update all product characteristics configurations with updated code of the characteristic.
    // Only when product characteristics is not linked with subset.
    final Entity prodchValue = ModelProvider.getInstance().getEntity(
        CharacteristicValue.ENTITY_NAME);
    final Property codeProperty = prodchValue.getProperty(CharacteristicValue.PROPERTY_CODE);
    if (event.getCurrentState(codeProperty) != event.getPreviousState(codeProperty)) {
      OBCriteria<ProductCharacteristic> productCharateristic = OBDal.getInstance().createCriteria(
          ProductCharacteristic.class);
      productCharateristic.add(Restrictions
          .isNull(ProductCharacteristic.PROPERTY_CHARACTERISTICSUBSET));
      OBContext.setAdminMode(true);
      try {
        ScrollableResults productChScroller = productCharateristic.scroll(ScrollMode.FORWARD_ONLY);
        int i = 0;
        while (productChScroller.next()) {
          ProductCharacteristic productch = (ProductCharacteristic) productChScroller.get()[0];
          OBCriteria<ProductCharacteristicConf> productCharateristicsConf = OBDal.getInstance()
              .createCriteria(ProductCharacteristicConf.class);
          productCharateristicsConf.add(Restrictions.eq(
              ProductCharacteristicConf.PROPERTY_CHARACTERISTICOFPRODUCT, productch));
          productCharateristicsConf.add(Restrictions.eq(
              ProductCharacteristicConf.PROPERTY_CHARACTERISTICVALUE, chv));

          ScrollableResults productChConfScroller = productCharateristicsConf
              .scroll(ScrollMode.FORWARD_ONLY);
          while (productChConfScroller.next()) {
            ProductCharacteristicConf conf = (ProductCharacteristicConf) productChConfScroller
                .get()[0];
            if (chv.getCode() != conf.getCode()) {
              conf.setCode(chv.getCode());
              OBDal.getInstance().save(conf);
            }
          }

          i++;
          if (i % 100 == 0) {
            OBDal.getInstance().getSession().clear();
          }
        }

      } finally {
        OBContext.restorePreviousMode();
      }
    }
  }
Performance
has duplicate defect 00268673.0PR14Q4 closed daniOpenbravo The manage variants process causes the server crash with a big amount of possible combinations. 
diff CharacteristicValueEventHandler.diff (4,548) 2015-03-25 19:15
https://issues.openbravo.com/file_download.php?file_id=7936&type=bug
Issue History
2014-07-23 20:34jecharriNew Issue
2014-07-23 20:34jecharriAssigned To => AugustoMauch
2014-07-23 20:34jecharriWeb browser => Google Chrome
2014-07-23 20:34jecharriModules => Core
2014-07-23 20:34jecharriResolution time => 1408399200
2014-07-23 20:34jecharriTriggers an Emergency Pack => No
2014-07-23 20:39jecharriWeb browserGoogle Chrome => Google Chrome
2014-07-23 20:39jecharriSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=6140#r6140
2014-07-23 20:51jecharriWeb browserGoogle Chrome => Google Chrome
2014-07-23 20:51jecharriProposed Solution updated
2014-07-23 20:58jecharriWeb browserGoogle Chrome => Google Chrome
2014-07-23 20:58jecharriSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=6141#r6141
2014-07-24 07:18alostaleTag Attached: Performance
2014-07-24 07:19alostaleRelationship addedhas duplicate 0026867
2014-07-24 07:20alostaleAssigned ToAugustoMauch => eduardo_Argal
2014-09-22 16:36jonalegriaesarteTarget Version => 3.0PR15Q1
2014-09-22 16:37jonalegriaesarteTarget Version3.0PR15Q1 => 3.0PR14Q4
2014-09-29 16:12jonalegriaesarteTarget Version3.0PR14Q4 => 3.0PR15Q1
2014-10-16 11:36eduardo_ArgalStatusnew => scheduled
2014-10-16 11:36eduardo_Argalfix_in_branch => pi
2014-12-22 12:37vmromanosWeb browserGoogle Chrome => Google Chrome
2014-12-22 12:37vmromanosTarget Version3.0PR15Q1 => 3.0PR15Q2
2014-12-22 12:37vmromanosfix_in_branchpi =>
2015-03-25 19:15eduardo_ArgalFile Added: CharacteristicValueEventHandler.diff
2015-03-25 19:16eduardo_ArgalNote Added: 0075982
2015-03-30 13:59jonalegriaesarteTarget Version3.0PR15Q2 => 3.0PR15Q3
2015-05-18 11:12hgbotCheckin
2015-05-18 11:12hgbotNote Added: 0077519
2015-05-18 11:12hgbotStatusscheduled => resolved
2015-05-18 11:12hgbotResolutionopen => fixed
2015-05-18 11:12hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/03198cfe71dfaaba2ff641430be536b6efc5eb84 [^]
2015-05-18 11:17eduardo_ArgalReview Assigned To => eduardo_Argal
2015-05-18 11:17eduardo_ArgalNote Added: 0077520
2015-05-18 11:17eduardo_ArgalStatusresolved => closed
2015-05-19 01:33hudsonbotCheckin
2015-05-19 01:33hudsonbotNote Added: 0077547

Notes
(0075982)
eduardo_Argal   
2015-03-25 19:16   
See attached patch
(0077519)
hgbot   
2015-05-18 11:12   
Repository: erp/devel/pi
Changeset: 03198cfe71dfaaba2ff641430be536b6efc5eb84
Author: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
Date: Mon May 18 11:06:08 2015 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/03198cfe71dfaaba2ff641430be536b6efc5eb84 [^]

Fixes issue 27170: Performance problems in CharacteristicValueEventHandler

onUpdate method has been changed to execute an update query instead of two OBCriteria queries, which improves the performance of the event handler.

---
M src/org/openbravo/event/CharacteristicValueEventHandler.java
---
(0077520)
eduardo_Argal   
2015-05-18 11:17   
Fix was tested and verified in a customer environment.
Code reviewed and tested.
Now after modifying existing value or inserting new one system throws one single update sentence, which saves most of the memory consumption
(0077547)
hudsonbot   
2015-05-19 01:33   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/bdd788358e65 [^]
Maturity status: Test