Skip to content

Commit

Permalink
Create a single repository to be shared by all calls to getScopedClient
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Jun 4, 2020
1 parent 0493978 commit c5e446a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions x-pack/plugins/spaces/server/spaces_service/spaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@ export class SpacesService {
return spaceId;
};

const internalRepositoryPromise = getStartServices().then(([coreStart]) =>
coreStart.savedObjects.createInternalRepository(['space'])
);

const getScopedClient = async (request: KibanaRequest) => {
const [coreStart] = await getStartServices();
const internalRepository = await internalRepositoryPromise;

return config$
.pipe(
take(1),
map((config) => {
const internalRepository = coreStart.savedObjects.createInternalRepository(['space']);

const callWithRequestRepository = coreStart.savedObjects.createScopedRepository(
request,
['space']
Expand All @@ -92,8 +96,7 @@ export class SpacesService {
internalRepository,
request
);
}),
take(1)
})
)
.toPromise();
};
Expand Down

0 comments on commit c5e446a

Please sign in to comment.