Iterate over '$scope.state.slaves/.frameworks' only once when
updating state in the WebUI.

The current implementation iterates over 'slaves' and 'frameworks'
twice: the first time to copy the state and the second time to
calculate statistics about that state. The iterations can be
collapsed into one without changing any functionality.

From: Ross Allen <ross...@mesosphe.re>
Review: https://reviews.apache.org/r/12741


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/680772c1
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/680772c1
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/680772c1

Branch: refs/heads/master
Commit: 680772c1a71ef1e18ecb0c3df0474052afc650f4
Parents: 9b0daff
Author: Benjamin Mahler <bmah...@twitter.com>
Authored: Thu Jul 18 16:43:23 2013 -0700
Committer: Benjamin Mahler <bmah...@twitter.com>
Committed: Thu Jul 18 16:43:23 2013 -0700

----------------------------------------------------------------------
 src/webui/master/static/js/controllers.js | 84 ++++++++++++--------------
 1 file changed, 40 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/680772c1/src/webui/master/static/js/controllers.js
----------------------------------------------------------------------
diff --git a/src/webui/master/static/js/controllers.js 
b/src/webui/master/static/js/controllers.js
index 2d4766f..dae12b6 100644
--- a/src/webui/master/static/js/controllers.js
+++ b/src/webui/master/static/js/controllers.js
@@ -164,21 +164,6 @@
     $scope.offers = {};
     $scope.completed_frameworks = {};
 
-    _.each($scope.state.slaves, function(slave) {
-      $scope.slaves[slave.id] = slave;
-    });
-
-    _.each($scope.state.frameworks, function(framework) {
-      $scope.frameworks[framework.id] = framework;
-      _.each(framework.offers, function(offer) {
-        $scope.offers[offer.id] = offer;
-      });
-    });
-
-    _.each($scope.state.completed_frameworks, function(framework) {
-      $scope.completed_frameworks[framework.id] = framework;
-    });
-
     // Update the stats.
     $scope.cluster = $scope.state.cluster;
     $scope.total_cpus = 0;
@@ -198,43 +183,54 @@
     $scope.activated_slaves = $scope.state.activated_slaves;
     $scope.deactivated_slaves = $scope.state.deactivated_slaves;
 
-    _.each($scope.slaves, function(slave) {
+    _.each($scope.state.slaves, function(slave) {
+      $scope.slaves[slave.id] = slave;
       $scope.total_cpus += slave.resources.cpus;
       $scope.total_mem += slave.resources.mem;
     });
 
-    _.each($scope.frameworks, function(framework) {
-        $scope.used_cpus += framework.resources.cpus;
-        $scope.used_mem += framework.resources.mem;
-        $scope.active_tasks += framework.tasks.length;
-        $scope.completed_tasks += framework.completed_tasks.length;
+    _.each($scope.state.frameworks, function(framework) {
+      $scope.frameworks[framework.id] = framework;
 
-        framework.cpus_share = 0;
-        if ($scope.total_cpus > 0) {
-          framework.cpus_share = framework.resources.cpus / $scope.total_cpus;
-        }
+      _.each(framework.offers, function(offer) {
+        $scope.offers[offer.id] = offer;
+      });
 
-        framework.mem_share = 0;
-        if ($scope.total_mem > 0) {
-          framework.mem_share = framework.resources.mem / $scope.total_mem;
-        }
+      $scope.used_cpus += framework.resources.cpus;
+      $scope.used_mem += framework.resources.mem;
+      $scope.active_tasks += framework.tasks.length;
+      $scope.completed_tasks += framework.completed_tasks.length;
 
-        framework.max_share = Math.max(framework.cpus_share, 
framework.mem_share);
+      framework.cpus_share = 0;
+      if ($scope.total_cpus > 0) {
+        framework.cpus_share = framework.resources.cpus / $scope.total_cpus;
+      }
 
-        // If the executor ID is empty, this is a command executor with an
-        // internal executor ID generated from the task ID.
-        // TODO(brenden): Remove this once
-        // https://issues.apache.org/jira/browse/MESOS-527 is fixed.
-        _.each(framework.tasks, function(task) {
-          if (!task.executor_id) {
-            task.executor_id = task.id;
-          }
-        });
-        _.each(framework.completed_tasks, function(task) {
-          if (!task.executor_id) {
-            task.executor_id = task.id;
-          }
-        });
+      framework.mem_share = 0;
+      if ($scope.total_mem > 0) {
+        framework.mem_share = framework.resources.mem / $scope.total_mem;
+      }
+
+      framework.max_share = Math.max(framework.cpus_share, 
framework.mem_share);
+
+      // If the executor ID is empty, this is a command executor with an
+      // internal executor ID generated from the task ID.
+      // TODO(brenden): Remove this once
+      // https://issues.apache.org/jira/browse/MESOS-527 is fixed.
+      _.each(framework.tasks, function(task) {
+        if (!task.executor_id) {
+          task.executor_id = task.id;
+        }
+      });
+      _.each(framework.completed_tasks, function(task) {
+        if (!task.executor_id) {
+          task.executor_id = task.id;
+        }
+      });
+    });
+
+    _.each($scope.state.completed_frameworks, function(framework) {
+      $scope.completed_frameworks[framework.id] = framework;
     });
 
     _.each($scope.offers, function(offer) {

Reply via email to