details: https://code.openbravo.com/erp/devel/pi/rev/4a43e052de88
changeset: 21409:4a43e052de88
user: Stefan Hühner <stefan.huehner <at> openbravo.com>
date: Wed Oct 30 18:52:53 2013 +0100
summary: Fixed 25051: Improve alertbackground process with high number of
alerts.
Improve performance of that process when it need to process a high number
of alerts created by an alertrule.
Push down the check if that alert has already been inserted into ad_alert
into the query getting the alerts instead of doing many small queries.
diffstat:
src/org/openbravo/erpCommon/ad_process/AlertProcess.java | 31 +++++-----
src/org/openbravo/erpCommon/ad_process/AlertProcess_data.xsql | 13 ----
2 files changed, 15 insertions(+), 29 deletions(-)
diffs (89 lines):
diff -r 5a980493ea05 -r 4a43e052de88
src/org/openbravo/erpCommon/ad_process/AlertProcess.java
--- a/src/org/openbravo/erpCommon/ad_process/AlertProcess.java Wed Oct 30
23:39:07 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_process/AlertProcess.java Wed Oct 30
18:52:53 2013 +0100
@@ -97,9 +97,11 @@
}
private static AlertProcessData[] selectAlert(ConnectionProvider
connectionProvider,
- String alertRule) throws ServletException {
+ String alertRule, String alertRuleId) throws ServletException {
String alertRuleSQL = (alertRule == null || alertRule.equals("")) ? "" :
alertRule;
- String strSql = "SELECT * FROM (" + alertRuleSQL + ") AAA";
+ String strSql = "SELECT * FROM (" + alertRuleSQL + ") AAA where not exists
("
+ + "select 1 from ad_alert a where a.ad_alertrule_id = ? "
+ + "and a.referencekey_id = aaa.referencekey_id and coalesce(a.status,
'NEW') != 'SOLVED')";
String dateTimeFormat =
OBPropertiesProvider.getInstance().getOpenbravoProperties()
.getProperty("dateTimeFormat.java");
@@ -110,6 +112,7 @@
try {
st = connectionProvider.getPreparedStatement(strSql);
+ st.setString(1, alertRuleId);
result = st.executeQuery();
while (result.next()) {
AlertProcessData objectAlertProcessData = new AlertProcessData();
@@ -238,7 +241,7 @@
if (!alertRule.sql.equals("")) {
try {
- alert = selectAlert(conn, alertRule.sql);
+ alert = selectAlert(conn, alertRule.sql, alertRule.adAlertruleId);
} catch (Exception ex) {
logger.log("Error processing: " + ex.getMessage() + "\n");
return;
@@ -251,22 +254,18 @@
;
for (int i = 0; i < alert.length; i++) {
- if (AlertProcessData
- .existsReference(conn, alertRule.adAlertruleId,
alert[i].referencekeyId).equals("0")) {
+ String adAlertId = SequenceIdData.getUUID();
- String adAlertId = SequenceIdData.getUUID();
+ logger.log("Inserting alert " + adAlertId + " org:" + alert[i].adOrgId
+ " client:"
+ + alert[i].adClientId + " reference key: " +
alert[i].referencekeyId + " created"
+ + alert[i].created + "\n");
- logger.log("Inserting alert " + adAlertId + " org:" +
alert[i].adOrgId + " client:"
- + alert[i].adClientId + " reference key: " +
alert[i].referencekeyId + " created"
- + alert[i].created + "\n");
+ insertAlert(conn, adAlertId, alert[i].adClientId, alert[i].adOrgId,
alert[i].created,
+ alert[i].createdby, alertRule.adAlertruleId, alert[i].recordId,
+ alert[i].referencekeyId, alert[i].description, alert[i].adUserId,
alert[i].adRoleId);
+ insertions++;
- insertAlert(conn, adAlertId, alert[i].adClientId, alert[i].adOrgId,
alert[i].created,
- alert[i].createdby, alertRule.adAlertruleId, alert[i].recordId,
- alert[i].referencekeyId, alert[i].description,
alert[i].adUserId, alert[i].adRoleId);
- insertions++;
-
- msg.append("\n\nAlert: " + alert[i].description + "\nRecord: " +
alert[i].recordId);
- }
+ msg.append("\n\nAlert: " + alert[i].description + "\nRecord: " +
alert[i].recordId);
}
if (insertions > 0) {
diff -r 5a980493ea05 -r 4a43e052de88
src/org/openbravo/erpCommon/ad_process/AlertProcess_data.xsql
--- a/src/org/openbravo/erpCommon/ad_process/AlertProcess_data.xsql Wed Oct
30 23:39:07 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_process/AlertProcess_data.xsql Wed Oct
30 18:52:53 2013 +0100
@@ -60,19 +60,6 @@
<Parameter name="sql" type="replace" optional="true" after="FROM ("
text="SELECT '' AS AD_CLIENT_ID, '' AS AD_ORG_ID, TO_DATE(NULL) AS CREATED, ''
AS CREATEDBY,'' AS UPDATED,'' AS UPDATEDBY,'' AS RECORD_ID, '' AS
REFERENCEKEY_ID, '' AS DESCRIPTION, '' AS ISACTIVE, '' AS AD_USER_ID, '' AS
AD_ROLE_ID FROM DUAL"/>
</SqlMethod>
- <SqlMethod name="existsReference" type="preparedStatement" return="string">
- <SqlMethodComment></SqlMethodComment>
- <Sql><![CDATA[
- SELECT COUNT(*) AS EXISTING
- FROM AD_ALERT
- WHERE AD_ALERTRULE_ID = ?
- AND REFERENCEKEY_ID = ?
- AND COALESCE(STATUS, 'NEW') != 'SOLVED'
- ]]></Sql>
- <Parameter name="alertRule"/>
- <Parameter name="ref"/>
- </SqlMethod>
-
<SqlMethod name="selectSQL" type="preparedStatement" return="multiple">
<SqlMethodComment></SqlMethodComment>
<Sql><![CDATA[
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits