Fixed issue 28968: When installing a module the rebuild takes long to start.
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Wed, 11 Mar 2015 10:42:05 +0100
changeset 26161 3610bd347abc
parent 26159 7fdaf0926663
child 26162 75c230345062
Fixed issue 28968: When installing a module the rebuild takes long to start.

The problem was that when installing a module the rebuild takes long to start.
This happened on environments with a lot of rows (Tested with 260.000 rows) on
the ad_session table.The result was this:

explain UPDATE AD_SESSION SET SESSION_ACTIVE='N' WHERE CREATEDBY<>'100'
Update on ad_session (cost=0.00..21546.15 rows=266303 width=147)

-> Seq Scan on ad_session (cost=0.00..21546.15 rows=266303 width=147)
Filter: ((createdby)::text <> '100'::text)
Approx time execution: 30000 ms

The new SQL Query to update is this:

explain UPDATE AD_SESSION SET SESSION_ACTIVE='N' WHERE CREATEDBY<>'100' and SESSION_ACTIVE='Y'
Update on ad_session (cost=0.42..4.44 rows=1 width=147)

-> Index Scan using ad_session_active_idx on ad_session (cost=0.42..4.44 rows=1 width=147)
Index Cond: (session_active = 'Y'::bpchar)
Filter: ((createdby)::text <> '100'::text)
Approx time execution: 30 ms

Adding the new condition "SESSION_ACTIVE = 'Y'" has been achieved to improve the performance.
src/org/openbravo/erpCommon/ad_process/ApplyModules.java
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Wed Mar 11 09:17:00 2015 +0100
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Wed Mar 11 10:42:05 2015 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2015 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -371,7 +371,7 @@
           + build.getMainSteps().get(0).getCode() + "'");
       ps2.executeUpdate();
       // We also cancel sessions opened for users different from the current one
-      updateSession = getPreparedStatement("UPDATE AD_SESSION SET SESSION_ACTIVE='N' WHERE CREATEDBY<>?");
+      updateSession = getPreparedStatement("UPDATE AD_SESSION SET SESSION_ACTIVE='N' WHERE CREATEDBY<>? and SESSION_ACTIVE='Y'");
       updateSession.setString(1, currentUser.getId());
       updateSession.executeUpdate();