From a02db6d5e9f6dc960a2949010401fb8a94ac75cb Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Mon, 2 Dec 2013 14:07:48 -0700 Subject: [PATCH 1/6] Eliminate idQueue property from filterSrv and querySrv. Replace with binary search for smallest id. Closes #730. Closes #739 --- src/app/components/kbn.js | 20 ++++++++++++++++++++ src/app/services/filterSrv.js | 15 +++++++-------- src/app/services/querySrv.js | 16 +++++++--------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index 7d8efef2e43..8a7bb392b74 100644 --- a/src/app/components/kbn.js +++ b/src/app/components/kbn.js @@ -479,6 +479,26 @@ function($, _, moment) { }); }; + // Find the smallest missing number in an array + kbn.smallestMissing = function(arr,start,end) { + start = start || 0; + end = end || arr.length-1; + + if(start > end) { + return end + 1; + } + if(start !== arr[start]) { + return start; + } + var middle = Math.floor((start + end) / 2); + + if (arr[middle] > middle) { + return kbn.smallestMissing(arr, start, middle); + } else { + return kbn.smallestMissing(arr, middle + 1, end); + } + }; + kbn.byteFormat = function(size, decimals) { var ext, steps = 0; decimals = decimals || 2; diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index e5def56bb2b..fa25390083d 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -14,14 +14,12 @@ define([ // Defaults for it var _d = { - idQueue : [], list : {}, ids : [] }; // For convenience var ejs = ejsResource(config.elasticsearch); - var _f = dashboard.current.services.filter; // Save a reference to this var self = this; @@ -34,7 +32,6 @@ define([ // Accessors self.list = dashboard.current.services.filter.list; self.ids = dashboard.current.services.filter.ids; - _f = dashboard.current.services.filter; _.each(self.list,function(f) { self.set(f,f.id,true); @@ -97,8 +94,6 @@ define([ delete self.list[id]; // This must happen on the full path also since _.without returns a copy self.ids = dashboard.current.services.filter.ids = _.without(self.ids,id); - _f.idQueue.unshift(id); - _f.idQueue.sort(function(v,k){return v-k;}); _r = true; } else { _r = false; @@ -230,10 +225,14 @@ define([ }; var nextId = function() { - if(_f.idQueue.length > 0) { - return _f.idQueue.shift(); + var idCount = dashboard.current.services.filter.ids.length; + if(idCount > 0) { + // Make a sorted copy of the ids array + var ids = _.clone(dashboard.current.services.filter.ids).sort(); + return kbn.smallestMissing(ids); } else { - return self.ids.length; + // No ids currently in list + return 0; } }; diff --git a/src/app/services/querySrv.js b/src/app/services/querySrv.js index 3b0b447d1d1..9cd6829c259 100644 --- a/src/app/services/querySrv.js +++ b/src/app/services/querySrv.js @@ -14,7 +14,6 @@ function (angular, _, config, kbn) { // Create an object to hold our service state on the dashboard dashboard.current.services.query = dashboard.current.services.query || {}; _.defaults(dashboard.current.services.query,{ - idQueue : [], list : {}, ids : [], }); @@ -31,7 +30,6 @@ function (angular, _, config, kbn) { // For convenience var ejs = ejsResource(config.elasticsearch); - var _q = dashboard.current.services.query; // Holds all actual queries, including all resolved abstract queries var resolvedQueries = []; @@ -176,10 +174,6 @@ function (angular, _, config, kbn) { delete self.list[id]; // This must happen on the full path also since _.without returns a copy self.ids = dashboard.current.services.query.ids = _.without(self.ids,id); - _q.idQueue.unshift(id); - _q.idQueue.sort(function(v,k){ - return v-k; - }); return true; } else { return false; @@ -246,10 +240,14 @@ function (angular, _, config, kbn) { }; var nextId = function() { - if(_q.idQueue.length > 0) { - return _q.idQueue.shift(); + var idCount = dashboard.current.services.query.ids.length; + if(idCount > 0) { + // Make a sorted copy of the ids array + var ids = _.clone(dashboard.current.services.query.ids).sort(); + return kbn.smallestMissing(ids); } else { - return self.ids.length; + // No ids currently in list + return 0; } }; From 3fe94734f45e88763d3c8c281af8fe15c094ddd4 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Mon, 2 Dec 2013 14:08:32 -0700 Subject: [PATCH 2/6] Remove idQueue from filter and query services in dashboards --- src/app/dashboards/blank.json | 11 ----------- src/app/dashboards/default.json | 11 ----------- src/app/dashboards/guided.json | 11 ----------- src/app/dashboards/logstash.json | 6 ------ src/app/dashboards/noted.json | 11 ----------- 5 files changed, 50 deletions(-) diff --git a/src/app/dashboards/blank.json b/src/app/dashboards/blank.json index 14a601da7af..f73ee1fc5a9 100644 --- a/src/app/dashboards/blank.json +++ b/src/app/dashboards/blank.json @@ -2,12 +2,6 @@ "title": "New Dashboard", "services": { "query": { - "idQueue": [ - 1, - 2, - 3, - 4 - ], "list": { "0": { "query": "*", @@ -21,11 +15,6 @@ ] }, "filter": { - "idQueue": [ - 0, - 1, - 2 - ], "list": {}, "ids": [] } diff --git a/src/app/dashboards/default.json b/src/app/dashboards/default.json index a0d31cc1c25..5a5bc905735 100644 --- a/src/app/dashboards/default.json +++ b/src/app/dashboards/default.json @@ -2,12 +2,6 @@ "title": "Introduction", "services": { "query": { - "idQueue": [ - 1, - 2, - 3, - 4 - ], "list": { "0": { "query": "*", @@ -23,11 +17,6 @@ ] }, "filter": { - "idQueue": [ - 0, - 1, - 2 - ], "list": {}, "ids": [] } diff --git a/src/app/dashboards/guided.json b/src/app/dashboards/guided.json index 13114ab450e..eabb77f9db9 100644 --- a/src/app/dashboards/guided.json +++ b/src/app/dashboards/guided.json @@ -2,12 +2,6 @@ "title": "Your Basic Dashboard", "services": { "query": { - "idQueue": [ - 1, - 2, - 3, - 4 - ], "list": { "0": { "query": "*", @@ -23,11 +17,6 @@ ] }, "filter": { - "idQueue": [ - 0, - 1, - 2 - ], "list": {}, "ids": [] } diff --git a/src/app/dashboards/logstash.json b/src/app/dashboards/logstash.json index 15ed4cf4eac..9bd1aac1550 100644 --- a/src/app/dashboards/logstash.json +++ b/src/app/dashboards/logstash.json @@ -2,9 +2,6 @@ "title": "Logstash Search", "services": { "query": { - "idQueue": [ - 1 - ], "list": { "0": { "query": "{{ARGS.query || '*'}}", @@ -20,9 +17,6 @@ ] }, "filter": { - "idQueue": [ - 1 - ], "list": { "0": { "type": "time", diff --git a/src/app/dashboards/noted.json b/src/app/dashboards/noted.json index c9b49b64667..8f2db5024b6 100644 --- a/src/app/dashboards/noted.json +++ b/src/app/dashboards/noted.json @@ -2,12 +2,6 @@ "title": "A few notes", "services": { "query": { - "idQueue": [ - 1, - 2, - 3, - 4 - ], "list": { "0": { "query": "*", @@ -23,11 +17,6 @@ ] }, "filter": { - "idQueue": [ - 0, - 1, - 2 - ], "list": {}, "ids": [] } From a14ead5ca787ec1ce5c08bd515bce48a1f91b2fb Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Mon, 2 Dec 2013 16:19:27 -0700 Subject: [PATCH 3/6] Improve performance in the table. Re #719 and #732 --- src/app/app.js | 6 +- src/app/components/require.config.js | 3 +- src/app/panels/table/editor.html | 4 +- src/app/panels/table/module.html | 20 +- src/vendor/angular/bindonce.js | 270 +++++++++++++++++++++++++++ 5 files changed, 289 insertions(+), 14 deletions(-) create mode 100644 src/vendor/angular/bindonce.js diff --git a/src/app/app.js b/src/app/app.js index e331a1b38e1..132e7f2b994 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -11,7 +11,8 @@ define([ 'angular-sanitize', 'angular-strap', 'angular-dragdrop', - 'extend-jquery' + 'extend-jquery', + 'bindonce' ], function (angular, $, _, appLevelRequire) { "use strict"; @@ -84,7 +85,8 @@ function (angular, $, _, appLevelRequire) { '$strap.directives', 'ngSanitize', 'ngDragDrop', - 'kibana' + 'kibana', + 'pasvaz.bindonce' ]; _.each('controllers directives factories services filters'.split(' '), diff --git a/src/app/components/require.config.js b/src/app/components/require.config.js index e987b4cbf73..a13dac6b458 100644 --- a/src/app/components/require.config.js +++ b/src/app/components/require.config.js @@ -20,6 +20,7 @@ require.config({ 'angular-sanitize': '../vendor/angular/angular-sanitize', timepicker: '../vendor/angular/timepicker', datepicker: '../vendor/angular/datepicker', + bindonce: '../vendor/angular/bindonce', underscore: 'components/underscore.extended', 'underscore-src': '../vendor/underscore', @@ -84,7 +85,7 @@ require.config({ 'angular-resource': ['angular'], 'angular-route': ['angular'], 'angular-touch': ['angular'], - + 'bindonce': ['angular'], 'angular-strap': ['angular', 'bootstrap','timepicker', 'datepicker'], timepicker: ['jquery', 'bootstrap'], diff --git a/src/app/panels/table/editor.html b/src/app/panels/table/editor.html index c09d9f198b9..3a4c36bd749 100644 --- a/src/app/panels/table/editor.html +++ b/src/app/panels/table/editor.html @@ -42,7 +42,7 @@
-
Trim Factor Trim fields to this long divided by # of rows
- +
Trim Factor Trim fields to this long divided by # of rows. Requires data refresh.
+
\ No newline at end of file diff --git a/src/app/panels/table/module.html b/src/app/panels/table/module.html index 426424f69d3..83e05f1a08b 100644 --- a/src/app/panels/table/module.html +++ b/src/app/panels/table/module.html @@ -8,7 +8,7 @@
-
+