From 475febd0048dcd5fc1a161556f0e909efec33405 Mon Sep 17 00:00:00 2001 From: James Westover Date: Fri, 26 Jan 2018 02:27:06 -0600 Subject: [PATCH] Fix typeahead to avoid generating new backend request on each keypress. (#10596) * Fix typeahead to not generate new request on each keypress. * Change to debounce method --- public/app/core/components/query_part/query_part_editor.ts | 4 ++-- public/app/core/directives/metric_segment.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/app/core/components/query_part/query_part_editor.ts b/public/app/core/components/query_part/query_part_editor.ts index 138da186238..c78ca8d74e6 100644 --- a/public/app/core/components/query_part/query_part_editor.ts +++ b/public/app/core/components/query_part/query_part_editor.ts @@ -123,11 +123,11 @@ export function queryPartEditorDirective($compile, templateSrv) { }); var typeahead = $input.data('typeahead'); - typeahead.lookup = function() { + typeahead.lookup = _.debounce(function() { this.query = this.$element.val() || ''; var items = this.source(this.query, $.proxy(this.process, this)); return items ? this.process(items) : items; - }; + }, 500); } $scope.showActionsMenu = function() { diff --git a/public/app/core/directives/metric_segment.js b/public/app/core/directives/metric_segment.js index 2754f8d8c6e..b11625227c7 100644 --- a/public/app/core/directives/metric_segment.js +++ b/public/app/core/directives/metric_segment.js @@ -129,11 +129,11 @@ function (_, $, coreModule) { $input.typeahead({ source: $scope.source, minLength: 0, items: 10000, updater: $scope.updater, matcher: $scope.matcher }); var typeahead = $input.data('typeahead'); - typeahead.lookup = function () { + typeahead.lookup = _.debounce(function() { this.query = this.$element.val() || ''; var items = this.source(this.query, $.proxy(this.process, this)); return items ? this.process(items) : items; - }; + }, 500); $button.keydown(function(evt) { // trigger typeahead on down arrow or enter key