ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-12800. App.alertNotificationMapper takes 4-5 seconds with 1000 notifications (onechiporenko)
Date Tue, 18 Aug 2015 09:39:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5c99c9b07 -> 424e07a5e


AMBARI-12800. App.alertNotificationMapper takes 4-5 seconds with 1000 notifications (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/424e07a5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/424e07a5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/424e07a5

Branch: refs/heads/trunk
Commit: 424e07a5e5735c72b1e4452a135dca71e17e4c29
Parents: 5c99c9b
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Tue Aug 18 12:26:03 2015 +0300
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Tue Aug 18 12:38:50 2015 +0300

----------------------------------------------------------------------
 .../app/mappers/alert_notification_mapper.js    | 35 +++++++++++++++-----
 1 file changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/424e07a5/ambari-web/app/mappers/alert_notification_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_notification_mapper.js b/ambari-web/app/mappers/alert_notification_mapper.js
index 728a2e7..95e2362 100644
--- a/ambari-web/app/mappers/alert_notification_mapper.js
+++ b/ambari-web/app/mappers/alert_notification_mapper.js
@@ -18,7 +18,9 @@
 var App = require('app');
 
 App.alertNotificationMapper = App.QuickDataMapper.create({
+
   model: App.AlertNotification,
+
   config: {
     id: 'AlertTarget.id',
     name: 'AlertTarget.name',
@@ -28,11 +30,17 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
   },
 
   map: function (json) {
+    if(Em.isNone(App.cache['previousAlertNotificationsFullMap'])) {
+      App.cache['previousAlertNotificationsFullMap'] = {};
+    }
+    console.time('App.alertNotificationMapper execution time');
     if (json.items) {
       var result = [];
       var notificationsProperties = {};
       var notificationsAlertStates = {};
       var groupsMap = App.cache['alertNotificationsGroupsMap'];
+      var notifications = {};
+      var self = this;
 
       json.items.forEach(function (item) {
         var notification = this.parseIt(item, this.config);
@@ -40,27 +48,38 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
         if (groups) {
           notification.groups = groups;
         }
-        result.push(notification);
+
+        var previousNotification = App.cache['previousAlertNotificationsFullMap'][notification.id]
? App.cache['previousAlertNotificationsFullMap'][notification.id] : {};
+        var changedFields = self.getDiscrepancies(notification, previousNotification, ['name',
'type', 'description', 'global', 'groups']);
+        if (Object.keys(changedFields).length) {
+          result.push(notification);
+        }
+
+        notifications[notification.id] = notification;
         notificationsProperties[item.AlertTarget.id] = item.AlertTarget.properties;
         notificationsAlertStates[item.AlertTarget.id] = item.AlertTarget.alert_states;
       }, this);
 
       App.store.loadMany(this.get('model'), result);
-      this.setProperties('properties', notificationsProperties);
-      this.setProperties('alertStates', notificationsAlertStates);
+      App.cache['previousAlertNotificationsFullMap'] = notifications;
+      this._setPropertiesToEachModel('properties', notificationsProperties);
+      this._setPropertiesToEachModel('alertStates', notificationsAlertStates);
     }
+    console.timeEnd('App.alertNotificationMapper execution time');
   },
 
   /**
    * Set values from <code>propertyMap</code> for <code>propertyName</code>
for each record in model
-   * @param propertyName
-   * @param propertiesMap record_id to value map
+   * @param {string} propertyName
+   * @param {object} propertiesMap record_id to value map
+   * @method setPropertiesToEachModel
+   * @private
    */
-  setProperties: function (propertyName, propertiesMap) {
-    var modelRecords = this.get('model').find();
+  _setPropertiesToEachModel: function (propertyName, propertiesMap) {
+    var modelsMap = this.get('modelsMap');
     for (var recordId in propertiesMap) {
       if (propertiesMap.hasOwnProperty(recordId)) {
-        modelRecords.findProperty('id', +recordId).set(propertyName, propertiesMap[recordId]);
+        App.AlertNotification.find(recordId).set(propertyName, propertiesMap[recordId]);
       }
     }
   }


Mime
View raw message