Skip to content

Commit 813578b

Browse files
committed
Memoize date functions that are called excessively to reduce overhead
1 parent f8cd84b commit 813578b

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

dashboard/js/app.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -1816,17 +1816,17 @@ function fixTime(timestamp) {
18161816
return timestamp;
18171817
}
18181818

1819-
function utcToString(timestamp) {
1819+
var utcToString = nanomemoize(function utcToString(timestamp) {
18201820
return (new Date(fixTime(timestamp))).toLocaleString();
1821-
}
1821+
});
18221822

1823-
function utcToTimeString(timestamp) {
1823+
var utcToTimeString = nanomemoize(function utcToTimeString(timestamp) {
18241824
return (new Date(fixTime(timestamp))).toLocaleTimeString();
1825-
}
1825+
});
18261826

1827-
function utcToDateString(timestamp) {
1827+
var utcToDateString = nanomemoize(function utcToDateString(timestamp) {
18281828
return (new Date(fixTime(timestamp))).toLocaleDateString();
1829-
}
1829+
});
18301830

18311831
function timeSince(time){
18321832
if (!time) return "never";
@@ -1919,14 +1919,10 @@ function adjustTimeOffset(time) {
19191919

19201920

19211921

1922-
var memoizedRenders = {};
19231922
app.filter('renderString', ['$sce', function($sce) {
19241923
return renderString.bind(null, $sce);
19251924
}]);
1926-
function renderString($sce, value) {
1927-
if (memoizedRenders[value]) {
1928-
return memoizedRenders[value];
1929-
}
1925+
var renderString = nanomemoize(function renderString($sce, value) {
19301926
var i = 0;
19311927
if (!value) return '';
19321928
var meta = {type: null, options: {}};
@@ -2072,7 +2068,7 @@ function renderString($sce, value) {
20722068
}
20732069
memoizedRenders[value] = result;
20742070
return result;
2075-
};
2071+
});
20762072

20772073
var wuIconForTwcCode = {
20782074
0: 'tstorms', // Tornado

dashboard/js/components/40.nano-memoize.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashboard/js/components/components.min.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashboard/js/modules/piston.module.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
686686
});
687687
};
688688

689-
$scope.formatVariableValue = function(variable, name) {
689+
$scope.formatVariableValue = nanomemoize(function(variable, name) {
690690
if ((variable.v == null) && !!name && $scope.localVars) {
691691
variable = $scope.copy(variable);
692692
variable.v = $scope.localVars[name];
@@ -709,7 +709,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
709709
return angular.toJson(variable.v);
710710
}
711711
return variable.v;
712-
}
712+
});
713713

714714
$scope.deleteDialog = function() {
715715
$scope.designer.dialog = ngDialog.open({

0 commit comments

Comments
 (0)