Fix leaky subscription (#45778)

This commit is contained in:
Jean-Louis Leysens 2019-09-18 12:08:20 +02:00 committed by GitHub
parent 60c4578587
commit a2f6e44fed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -24,6 +24,7 @@ import { initializeInput } from '../input';
import { initializeOutput } from '../output';
import init from '../app';
import { getEndpointFromPosition } from '../autocomplete';
import mappings from '../mappings';
import { DOC_LINK_VERSION } from 'ui/documentation_links';
// welcome message
@ -134,4 +135,8 @@ module.controller('SenseController', function SenseController($scope, $timeout,
event.preventDefault();
input.focus();
};
$scope.$on('$destroy', () => {
mappings.clearSubscriptions();
});
});

View file

@ -289,10 +289,14 @@ function retrieveSettings(settingsKey, settingsToRetrieve) {
// unchanged alone (both selected and unselected).
// 3. Poll: Use saved. Fetch selected. Ignore unselected.
function retrieveAutoCompleteInfo(settingsToRetrieve = settings.getAutocomplete()) {
function clearSubscriptions() {
if (pollTimeoutId) {
clearTimeout(pollTimeoutId);
}
}
function retrieveAutoCompleteInfo(settingsToRetrieve = settings.getAutocomplete()) {
clearSubscriptions();
const mappingPromise = retrieveSettings('fields', settingsToRetrieve);
const aliasesPromise = retrieveSettings('indices', settingsToRetrieve);
@ -346,4 +350,5 @@ export default {
expandAliases,
clear,
retrieveAutoCompleteInfo,
clearSubscriptions
};