Skip to content

Commit

Permalink
Cancel Discover fetch requests if a new one is submitted (#39963)
Browse files Browse the repository at this point in the history
* Cancel discover fetch requests if a nnew one is submitted

* Add comment

* Remove unused translations
  • Loading branch information
lukasolson committed Jul 10, 2019
1 parent f8fb833 commit 6a0d827
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,9 @@ function discoverController(

$scope.updateDataSource()
.then(function () {
$scope.$listen(timefilter, 'fetch', function () {
$scope.fetch();
});
$scope.$listen(timefilter, 'refreshIntervalUpdate', () => {
$scope.updateRefreshInterval();
});
$scope.$listen(timefilter, 'timeUpdate', () => {
$scope.updateTime();
});
$scope.$listen(timefilter, 'autoRefreshFetch', $scope.fetch);
$scope.$listen(timefilter, 'refreshIntervalUpdate', $scope.updateRefreshInterval);
$scope.$listen(timefilter, 'timeUpdate', $scope.updateTime);

$scope.$watchCollection('state.sort', function (sort) {
if (!sort) return;
Expand Down Expand Up @@ -710,20 +704,30 @@ function discoverController(

$scope.updateTime();

// Abort any in-progress requests before fetching again
$scope.searchSource.cancelQueued();

$scope.updateDataSource()
.then(setupVisualization)
.then(function () {
$state.save();
$scope.fetchStatus = fetchStatuses.LOADING;
logInspectorRequest();
return courier.fetch();
return $scope.searchSource.fetch();
})
.then(onResults)
.catch((error) => {
toastNotifications.addError(error, {
title: i18n.translate('kbn.discover.discoverError', {
defaultMessage: 'Discover error',
}),
});
const fetchError = getPainlessError(error);

if (fetchError) {
$scope.fetchError = fetchError;
} else {
toastNotifications.addError(error, {
title: i18n.translate('kbn.discover.errorLoadingData', {
defaultMessage: 'Error loading data',
}),
});
}
});
};

Expand Down Expand Up @@ -769,8 +773,6 @@ function discoverController(
});

$scope.fetchStatus = fetchStatuses.COMPLETE;

return $scope.searchSource.onResults().then(onResults);
}

let inspectorRequest;
Expand All @@ -796,29 +798,6 @@ function discoverController(
.ok({ json: resp });
}

function startSearching() {
return $scope.searchSource.onResults()
.then(onResults)
.catch((error) => {
const fetchError = getPainlessError(error);

if (fetchError) {
$scope.fetchError = fetchError;
} else {
toastNotifications.addError(error, {
title: i18n.translate('kbn.discover.errorLoadingData', {
defaultMessage: 'Error loading data',
}),
});
}

// Restart. This enables auto-refresh functionality.
startSearching();
});
}

startSearching();

$scope.updateTime = function () {
$scope.timeRange = {
from: dateMath.parse(timefilter.getTime().from),
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,6 @@
"kbn.discover.bucketIntervalTooltip.tooManyBucketsText": "バケットが多すぎます",
"kbn.discover.discoverBreadcrumbTitle": "ディスカバリ",
"kbn.discover.discoverDescription": "ドキュメントにクエリをかけたりフィルターを適用することで、データをインタラクティブに閲覧できます。",
"kbn.discover.discoverError": "ディスカバリエラー",
"kbn.discover.discoverTitle": "ディスカバー",
"kbn.discover.documentsAriaLabel": "ドキュメント",
"kbn.discover.errorLoadingData": "データの読み込み中にエラーが発生",
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,6 @@
"kbn.discover.bucketIntervalTooltip.tooManyBucketsText": "过多的存储桶",
"kbn.discover.discoverBreadcrumbTitle": "Discover",
"kbn.discover.discoverDescription": "通过查询和筛选原始文档来以交互方式浏览您的数据。",
"kbn.discover.discoverError": "Discover 错误",
"kbn.discover.discoverTitle": "Discover",
"kbn.discover.documentsAriaLabel": "文档",
"kbn.discover.errorLoadingData": "加载数据时出错",
Expand Down Expand Up @@ -10918,4 +10917,4 @@
"xpack.watcher.watchActions.logging.logTextIsRequiredValidationMessage": "“日志文本”必填。",
"xpack.watcher.watcherDescription": "通过创建、管理和监测警报来检测数据中的更改。"
}
}
}

0 comments on commit 6a0d827

Please sign in to comment.