-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Optimize saved objects getScopedClient and HTTP API #68221
Changes from all commits
c5e446a
ef30e36
fa04609
cc98fa6
9ffcf55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -136,7 +136,7 @@ export class SavedObjectsRepository { | |||||
injectedConstructor: any = SavedObjectsRepository | ||||||
): ISavedObjectsRepository { | ||||||
const mappings = migrator.getActiveMappings(); | ||||||
const allTypes = Object.keys(getRootPropertiesObjects(mappings)); | ||||||
const allTypes = typeRegistry.getAllTypes().map((t) => t.name); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apparently Pierre already refactored many places where we use this round about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some Very surprised There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably it's not
v8 cannot optimizie this case https://richardartoul.github.io/jekyll/update/2015/04/26/hidden-classes.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I misread and thought it was just a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the line that showed up in the profiler and took almost 5ms:
|
||||||
const serializer = new SavedObjectsSerializer(typeRegistry); | ||||||
const visibleTypes = allTypes.filter((type) => !typeRegistry.isHidden(type)); | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return config$ | ||
.pipe( | ||
take(1), | ||
map((config) => { | ||
const internalRepository = coreStart.savedObjects.createInternalRepository(['space']); | ||
|
||
const callWithRequestRepository = coreStart.savedObjects.createScopedRepository( | ||
request, | ||
['space'] | ||
|
@@ -92,8 +96,7 @@ export class SpacesService { | |
internalRepository, | ||
request | ||
); | ||
}), | ||
take(1) | ||
}) | ||
) | ||
.toPromise(); | ||
}; | ||
|
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.
The spaces plugin takes a config value for every
getScopedClient
call (every incoming request). This does config validation for this config path each time.kibana/x-pack/plugins/spaces/server/spaces_service/spaces_service.ts
Lines 75 to 82 in c5e446a
We could optimize the plugin to not take a new config value every time but only if a new value was emitted, but this felt like a better fix that will probably benefit other places.