SEED-platform / seed

Standard Energy Efficiency Data (SEED) Platform™ is a web-based application that helps organizations easily manage data on the energy performance of large groups of buildings.
Other
106 stars 55 forks source link

Render scenario ui-grid on expand #4599

Closed perryr16 closed 2 months ago

perryr16 commented 3 months ago

Any background context you want to provide?

The Scenarios & Measures section of the inventory detail page features a table of scenarios that can be expanded to show a nested ui-grid of the associated measures. Properties with numerous scenarios/measures can experience long loading times as each scenario's ui-grid introduces watchers that can slow down angular's performance.

What's this PR do?

Below is some bench marking with a property that has 8 scenarios, 6 of which have 1-3 measures (10 measures total). Description Number of Watchers
Current implementation 4200
Removing the scenarios and measures section 500
Proposed Solution 850

How should this be manually tested?

Load the property detail of a property with several scenarios/measures

What are the relevant tickets?

4597

Screenshots (if appropriate)

perryr16 commented 2 months ago

I used the following script to count the number of watchers on the page. Just paste this into the dev tools console, no break points, just console. source

function getWatchers(root) {
  root = angular.element(root || document.documentElement);
  var watcherCount = 0;

  function getElemWatchers(element) {
    var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
    var scopeWatchers = getWatchersFromScope(element.data().$scope);
    var watchers = scopeWatchers.concat(isolateWatchers);
    angular.forEach(element.children(), function (childElement) {
      watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
    });
    return watchers;
  }

  function getWatchersFromScope(scope) {
    if (scope) {
      return scope.$$watchers || [];
    } else {
      return [];
    }
  }

  return getElemWatchers(root);
}
getWatchers().length