-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Management] Provide a way to fetch index pattern titles #13030
Merged
chrisronline
merged 3 commits into
elastic:master
from
chrisronline:enhancement/get_index_pattern_titles
Jul 24, 2017
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 14 additions & 12 deletions
26
src/ui/public/index_patterns/_get_ids.js → src/ui/public/index_patterns/_get.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
import _ from 'lodash'; | ||
import { SavedObjectsClientProvider } from 'ui/saved_objects'; | ||
|
||
export function IndexPatternsGetIdsProvider(Private) { | ||
export function IndexPatternsGetProvider(Private) { | ||
const savedObjectsClient = Private(SavedObjectsClientProvider); | ||
|
||
// many places may require the id list, so we will cache it separately | ||
// didn't incorporate with the indexPattern cache to prevent id collisions. | ||
let cachedPromise; | ||
const cachedPromises = {}; | ||
|
||
const getIds = function () { | ||
if (cachedPromise) { | ||
const get = function (field) { | ||
if (cachedPromises[field]) { | ||
// return a clone of the cached response | ||
return cachedPromise.then(function (cachedResp) { | ||
return cachedPromises[field].then(function (cachedResp) { | ||
return _.clone(cachedResp); | ||
}); | ||
} | ||
|
||
cachedPromise = savedObjectsClient.find({ | ||
cachedPromises[field] = savedObjectsClient.find({ | ||
type: 'index-pattern', | ||
fields: [], | ||
perPage: 10000 | ||
}).then(resp => { | ||
return resp.savedObjects.map(obj => obj.id); | ||
return resp.savedObjects.map(obj => _.get(obj, field)); | ||
}); | ||
|
||
// ensure that the response stays pristine by cloning it here too | ||
return cachedPromise.then(function (resp) { | ||
return cachedPromises[field].then(function (resp) { | ||
return _.clone(resp); | ||
}); | ||
}; | ||
|
||
getIds.clearCache = function () { | ||
cachedPromise = null; | ||
return (field) => { | ||
const getter = get.bind(get, field); | ||
getter.clearCache = function () { | ||
delete cachedPromises[field]; | ||
}; | ||
return getter; | ||
}; | ||
|
||
return getIds; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the
IndexPatternsProvider
would clear the complete cache whenever it was invalidated. With this change, only the part of the cache used by the respective user is cleared. This seems like a dangerous way to end up with everything sitting in memory forever.I wonder if we should only cache IDs, and simply fetch other things on demand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup great point. I'm honestly not sure if caching will provide much benefit as it's not clear how consumers will use this for non-ids, but it made sense to me (at the time) to keep the behavior consistent. The previous callers to
clearCache
were only clearing cache around ids so it felt odd to clear the entire cache, but that might be the right call, or as you eluded to, maybe just not bother caching non-ids requests entirely.I'm open to changing it.