Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A317A18D28 for ; Wed, 12 Aug 2015 12:40:54 +0000 (UTC) Received: (qmail 82299 invoked by uid 500); 12 Aug 2015 12:40:54 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 82274 invoked by uid 500); 12 Aug 2015 12:40:54 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 82265 invoked by uid 99); 12 Aug 2015 12:40:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Aug 2015 12:40:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5207FE17EE; Wed, 12 Aug 2015 12:40:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: onechiporenko@apache.org To: commits@ambari.apache.org Message-Id: <78b9ff9a172d4d92a13a47325bb13fbb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-12739. Switching alert group in the "manage alert groups popup" is too slow (onechiporenko) Date: Wed, 12 Aug 2015 12:40:54 +0000 (UTC) Repository: ambari Updated Branches: refs/heads/trunk 0613c0a8a -> 4b07879b3 AMBARI-12739. Switching alert group in the "manage alert groups popup" is too slow (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4b07879b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4b07879b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4b07879b Branch: refs/heads/trunk Commit: 4b07879b3a3bde37319c4e8457088a588e70504f Parents: 0613c0a Author: Oleg Nechiporenko Authored: Wed Aug 12 15:12:52 2015 +0300 Committer: Oleg Nechiporenko Committed: Wed Aug 12 15:40:17 2015 +0300 ---------------------------------------------------------------------- .../alerts/manage_alert_groups_controller.js | 69 +++++++++++++------- .../service/manage_config_groups_controller.js | 24 +++++-- 2 files changed, 67 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/4b07879b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js index 2ca2536..ed9a607 100644 --- a/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js +++ b/ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js @@ -107,7 +107,35 @@ App.ManageAlertGroupsController = Em.Controller.extend({ * observes if any group changed including: group name, newly created group, deleted group, group with definitions/notifications changed * @type {{toDelete: App.AlertGroup[], toSet: App.AlertGroup[], toCreate: App.AlertGroup[]}} */ - defsModifiedAlertGroups: function () { + defsModifiedAlertGroups: {}, + + /** + * Determines if some group was edited/created/deleted + * @type {boolean} + */ + isDefsModified: function () { + var modifiedGroups = this.get('defsModifiedAlertGroups'); + if (!this.get('isLoaded')) { + return false; + } + return !!(modifiedGroups.toSet.length || modifiedGroups.toCreate.length || modifiedGroups.toDelete.length); + }.property('defsModifiedAlertGroups'), + + /** + * Check when some config group was changed and updates defsModifiedAlertGroups once + * @method defsModifiedAlertGroupsObs + */ + defsModifiedAlertGroupsObs: function() { + Em.run.once(this, this.defsModifiedAlertGroupsObsOnce); + }.observes('selectedAlertGroup.definitions.@each', 'selectedAlertGroup.definitions.length', 'selectedAlertGroup.notifications.@each', 'selectedAlertGroup.notifications.length', 'alertGroups', 'isLoaded'), + + /** + * Update defsModifiedAlertGroups-value + * Called once in the defsModifiedAlertGroupsObs + * @method defsModifiedAlertGroupsObsOnce + * @returns {boolean} + */ + defsModifiedAlertGroupsObsOnce: function() { if (!this.get('isLoaded')) { return false; } @@ -116,20 +144,28 @@ App.ManageAlertGroupsController = Em.Controller.extend({ var groupsToCreate = []; var groups = this.get('alertGroups'); //current alert groups var originalGroups = this.get('originalAlertGroups'); // original alert groups + var mappedOriginalGroups = {}; // map is faster than `originalGroups.findProperty('id', ...)` + originalGroups.forEach(function(group) { + mappedOriginalGroups[group.get('id')] = group; + }); var originalGroupsIds = originalGroups.mapProperty('id'); + groups.forEach(function (group) { - var originalGroup = originalGroups.findProperty('id', group.get('id')); + var originalGroup = mappedOriginalGroups[group.get('id')]; if (originalGroup) { // should update definitions or notifications - if (!(JSON.stringify(group.get('definitions').slice().sort()) === JSON.stringify(originalGroup.get('definitions').slice().sort())) - || !(JSON.stringify(group.get('notifications').slice().sort()) === JSON.stringify(originalGroup.get('notifications').slice().sort()))) { + if (JSON.stringify(group.get('definitions').slice().sort()) !== JSON.stringify(originalGroup.get('definitions').slice().sort()) + || JSON.stringify(group.get('notifications').slice().sort()) !== JSON.stringify(originalGroup.get('notifications').slice().sort())) { groupsToSet.push(group.set('id', originalGroup.get('id'))); - } else if (group.get('name') !== originalGroup.get('name')) { + } + else + if (group.get('name') !== originalGroup.get('name')) { // should update name groupsToSet.push(group.set('id', originalGroup.get('id'))); } originalGroupsIds = originalGroupsIds.without(group.get('id')); - } else { + } + else { // should add new group groupsToCreate.push(group); } @@ -137,25 +173,14 @@ App.ManageAlertGroupsController = Em.Controller.extend({ // should delete groups originalGroupsIds.forEach(function (id) { groupsToDelete.push(originalGroups.findProperty('id', id)); - }, this); - return { + }); + + this.set('defsModifiedAlertGroups', { toDelete: groupsToDelete, toSet: groupsToSet, toCreate: groupsToCreate - }; - }.property('selectedAlertGroup.definitions.@each', 'selectedAlertGroup.definitions.length', 'selectedAlertGroup.notifications.@each', 'selectedAlertGroup.notifications.length', 'alertGroups', 'isLoaded'), - - /** - * Determines if some group was edited/created/deleted - * @type {boolean} - */ - isDefsModified: function () { - var modifiedGroups = this.get('defsModifiedAlertGroups'); - if (!this.get('isLoaded')) { - return false; - } - return !!(modifiedGroups.toSet.length || modifiedGroups.toCreate.length || modifiedGroups.toDelete.length); - }.property('defsModifiedAlertGroups'), + }); + }, /** * Load all Alert Notifications from server http://git-wip-us.apache.org/repos/asf/ambari/blob/4b07879b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js index b2da99b..30055c6 100644 --- a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js +++ b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js @@ -144,7 +144,23 @@ App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, { * toCreate: App.ConfigGroup[] * }} */ - hostsModifiedConfigGroups: function () { + hostsModifiedConfigGroups: {}, + + /** + * Check when some config group was changed and updates hostsModifiedConfigGroups once + * @method hostsModifiedConfigGroupsObs + */ + hostsModifiedConfigGroupsObs: function() { + Em.run.once(this, this.hostsModifiedConfigGroupsObsOnce); + }.observes('selectedConfigGroup.hosts.@each', 'selectedConfigGroup.hosts.length', 'selectedConfigGroup.description', 'configGroups', 'isLoaded'), + + /** + * Update hostsModifiedConfigGroups-value + * Called once in the hostsModifiedConfigGroupsObs + * @method hostsModifiedConfigGroupsObsOnce + * @returns {boolean} + */ + hostsModifiedConfigGroupsObsOnce: function() { if (!this.get('isLoaded')) { return false; } @@ -181,14 +197,14 @@ App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, { originalGroupsIds.forEach(function (id) { groupsToDelete.push(originalGroupsMap[id]); }, this); - return { + this.set('hostsModifiedConfigGroups', { toClearHosts: groupsToClearHosts, toDelete: groupsToDelete, toSetHosts: groupsToSetHosts, toCreate: groupsToCreate, initialGroups: originalGroupsCopy - }; - }.property('selectedConfigGroup.hosts.@each', 'selectedConfigGroup.hosts.length', 'selectedConfigGroup.description', 'configGroups', 'isLoaded'), + }); + }, /** * Determines if some changes were done with config groups