From b2e544af3c0514cfb468e771cfb4517ce51ed93b Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 12 Apr 2020 22:09:16 -0400 Subject: [PATCH] APIv4 Explorer - performance boost with less intensive loops --- ang/api4Explorer/Explorer.html | 8 ++++---- ang/api4Explorer/Explorer.js | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index c190c7faa21f..a95562f55ebb 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -31,7 +31,7 @@

-
-
+
-
+
-
+
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index a9f0459c48fe..32c944144d27 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -222,12 +222,30 @@ } }; - $scope.isSpecial = function(name) { - var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having']; + // Gets generic params for use in one-time binding loops + $scope.getGenericParams = function(paramType, defaultNull) { + // Returns undefined if params are not yet set; one-time bindings will stabilize when this function returns a value + if (_.isEmpty($scope.availableParams)) { + return; + } + var genericParams = {}, + specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having']; if ($scope.availableParams.limit && $scope.availableParams.offset) { specialParams.push('limit', 'offset'); } - return _.contains(specialParams, name); + _.each($scope.availableParams, function(param, name) { + if (_.contains(specialParams, name)) { + return; + } + if (typeof paramType !== 'undefined' && !_.contains(paramType, param.type[0])) { + return; + } + if (typeof defaultNull !== 'undefined' && ((param.default === null) !== defaultNull)) { + return; + } + genericParams[name] = param; + }); + return genericParams; }; $scope.selectRowCount = function() {