-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Management] Provide a way to fetch index pattern titles (#13030)
* Refactor how `get_ids` works to enable fetching other properties of index patterns, specifically the `title` or name * Remove unnecessary lines * Only cache for `id` calls
- Loading branch information
1 parent
811e692
commit eb9f8a5
Showing
4 changed files
with
28 additions
and
18 deletions.
There are no files selected for viewing
32 changes: 20 additions & 12 deletions
32
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,46 @@ | ||
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; | ||
let cachedIdPromise; | ||
|
||
const getIds = function () { | ||
if (cachedPromise) { | ||
const get = function (field) { | ||
if (field === 'id' && cachedIdPromise) { | ||
// return a clone of the cached response | ||
return cachedPromise.then(function (cachedResp) { | ||
return cachedIdPromise.then(function (cachedResp) { | ||
return _.clone(cachedResp); | ||
}); | ||
} | ||
|
||
cachedPromise = savedObjectsClient.find({ | ||
const promise = 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)); | ||
}); | ||
|
||
if (field === 'id') { | ||
cachedIdPromise = promise; | ||
} | ||
|
||
// ensure that the response stays pristine by cloning it here too | ||
return cachedPromise.then(function (resp) { | ||
return promise.then(function (resp) { | ||
return _.clone(resp); | ||
}); | ||
}; | ||
|
||
getIds.clearCache = function () { | ||
cachedPromise = null; | ||
return (field) => { | ||
const getter = get.bind(get, field); | ||
if (field === 'id') { | ||
getter.clearCache = function () { | ||
cachedIdPromise = null; | ||
}; | ||
} | ||
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