ambari git commit: AMBARI-12800. App.alertNotificationMapper takes 4-5 seconds with 1000 notifications (onechiporenko)
Repository: ambari Updated Branches: refs/heads/branch-2.1 08a4b97be -> 9f75874c4 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/9f75874c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9f75874c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9f75874c Branch: refs/heads/branch-2.1 Commit: 9f75874c4e6e840afd349667e23bbb808ed450e3 Parents: 08a4b97 Author: Oleg Nechiporenko Authored: Tue Aug 18 12:26:03 2015 +0300 Committer: Oleg Nechiporenko Committed: Tue Aug 18 12:26:03 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/9f75874c/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 propertyMap for propertyName 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]); } } }
ambari git commit: AMBARI-12800. App.alertNotificationMapper takes 4-5 seconds with 1000 notifications (onechiporenko)
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 Authored: Tue Aug 18 12:26:03 2015 +0300 Committer: Oleg Nechiporenko 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 propertyMap for propertyName 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]); } } }