Skip to content

Commit

Permalink
defer loading visualization saved objects so they can be loaded in a …
Browse files Browse the repository at this point in the history
…single _mget
  • Loading branch information
nreese committed Jan 24, 2017
1 parent 9c28e63 commit 5c1344e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function loadSavedObject(loaders, panel) {
if (!loader) {
throw new Error(`No loader for object of type ${panel.type}`);
}
return loader.get(panel.id)
const isDefered = true;
return loader.get(panel.id, isDefered)
.then(savedObj => ({ savedObj, editUrl: loader.urlFor(panel.id) }));
}
10 changes: 8 additions & 2 deletions src/ui/public/courier/saved_object/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function SavedObjectFactory(esAdmin, kbnIndex, Promise, Private,
* @return {Promise}
* @resolved {SavedObject}
*/
this.init = _.once(() => {
this.init = _.once((isDefered) => {
// ensure that the type is defined
if (!type) throw new Error('You must define a type name to use SavedObject objects.');

Expand Down Expand Up @@ -166,7 +166,13 @@ export default function SavedObjectFactory(esAdmin, kbnIndex, Promise, Private,
}

// fetch the object from ES
return docSource.fetch().then(this.applyESResp);
if (isDefered) {
const defer = Promise.defer();
docSource._createRequest(defer);
return defer.promise.then(this.applyESResp);
} else {
return docSource.fetch().then(this.applyESResp);
}
})
.then(() => {
return customInit.call(this);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/courier/saved_object/saved_object_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class SavedObjectLoader {
* @param id
* @returns {Promise<SavedObject>}
*/
get(id) {
return (new this.Class(id)).init();
get(id, isDefered) {
return (new this.Class(id)).init(isDefered);
}

urlFor(id) {
Expand Down

0 comments on commit 5c1344e

Please sign in to comment.