mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
* Create a single repository to be shared by all calls to getScopedClient * Cache migrator.getActiveMappings to improve createRepository * Use typeregistry.getAllTypes instead of getRootPropertiesObjects(mappings) * Don't validate plugin's config every time it's read * Fix saved_objects_mixin Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
a2e0a7eb67
commit
af07d650e6
5 changed files with 17 additions and 11 deletions
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { map } from 'rxjs/operators';
|
||||
import { map, shareReplay } from 'rxjs/operators';
|
||||
import { combineLatest } from 'rxjs';
|
||||
import { CoreContext } from '../core_context';
|
||||
import { PluginWrapper } from './plugin';
|
||||
|
@ -107,8 +107,8 @@ export function createPluginInitializerContext(
|
|||
* @param ConfigClass A class (not an instance of a class) that contains a
|
||||
* static `schema` that we validate the config at the given `path` against.
|
||||
*/
|
||||
create() {
|
||||
return coreContext.configService.atPath(pluginManifest.configPath);
|
||||
create<T>() {
|
||||
return coreContext.configService.atPath<T>(pluginManifest.configPath).pipe(shareReplay(1));
|
||||
},
|
||||
createIfExists() {
|
||||
return coreContext.configService.optionalAtPath(pluginManifest.configPath);
|
||||
|
|
|
@ -74,6 +74,7 @@ export class KibanaMigrator {
|
|||
private readonly status$ = new BehaviorSubject<KibanaMigratorStatus>({
|
||||
status: 'waiting',
|
||||
});
|
||||
private readonly activeMappings: IndexMapping;
|
||||
|
||||
/**
|
||||
* Creates an instance of KibanaMigrator.
|
||||
|
@ -100,6 +101,9 @@ export class KibanaMigrator {
|
|||
validateDoc: docValidator(savedObjectValidations || {}),
|
||||
log: this.log,
|
||||
});
|
||||
// Building the active mappings (and associated md5sums) is an expensive
|
||||
// operation so we cache the result
|
||||
this.activeMappings = buildActiveMappings(this.mappingProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,7 +176,7 @@ export class KibanaMigrator {
|
|||
*
|
||||
*/
|
||||
public getActiveMappings(): IndexMapping {
|
||||
return buildActiveMappings(this.mappingProperties);
|
||||
return this.activeMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -135,7 +135,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);
|
||||
const serializer = new SavedObjectsSerializer(typeRegistry);
|
||||
const visibleTypes = allTypes.filter((type) => !typeRegistry.isHidden(type));
|
||||
|
||||
|
|
|
@ -27,14 +27,13 @@ import {
|
|||
importSavedObjectsFromStream,
|
||||
resolveSavedObjectsImportErrors,
|
||||
} from '../../../core/server/saved_objects';
|
||||
import { getRootPropertiesObjects } from '../../../core/server/saved_objects/mappings';
|
||||
import { convertTypesToLegacySchema } from '../../../core/server/saved_objects/utils';
|
||||
|
||||
export function savedObjectsMixin(kbnServer, server) {
|
||||
const migrator = kbnServer.newPlatform.__internals.kibanaMigrator;
|
||||
const typeRegistry = kbnServer.newPlatform.start.core.savedObjects.getTypeRegistry();
|
||||
const mappings = migrator.getActiveMappings();
|
||||
const allTypes = Object.keys(getRootPropertiesObjects(mappings));
|
||||
const allTypes = typeRegistry.getAllTypes().map((t) => t.name);
|
||||
const schema = new SavedObjectsSchema(convertTypesToLegacySchema(typeRegistry.getAllTypes()));
|
||||
const visibleTypes = allTypes.filter((type) => !schema.isHiddenType(type));
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
@ -92,8 +96,7 @@ export class SpacesService {
|
|||
internalRepository,
|
||||
request
|
||||
);
|
||||
}),
|
||||
take(1)
|
||||
})
|
||||
)
|
||||
.toPromise();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue