浏览代码

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

Oleg Nechiporenko 10 年之前
父节点
当前提交
424e07a5e5
共有 1 个文件被更改,包括 27 次插入8 次删除
  1. 27 8
      ambari-web/app/mappers/alert_notification_mapper.js

+ 27 - 8
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]);
       }
     }
   }