mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 03:01:51 +08:00
Plugin Loader: Don't load an app plugin multiple times (#107579)
* fix(plugin_loader): don't import an app plugin twice * review: extract IIFE to a separate function (async part of plugin loading) * fix: remove code for testing
This commit is contained in:
@ -187,16 +187,21 @@ export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise<Gene
|
||||
});
|
||||
}
|
||||
|
||||
// Only successfully loaded plugins are cached
|
||||
const importedAppPlugins: Record<string, AppPlugin> = {};
|
||||
// Cache for import promises to prevent duplicate imports
|
||||
const importPromises: Record<string, Promise<AppPlugin>> = {};
|
||||
|
||||
export async function importAppPlugin(meta: PluginMeta): Promise<AppPlugin> {
|
||||
const pluginId = meta.id;
|
||||
|
||||
if (importedAppPlugins[pluginId]) {
|
||||
return importedAppPlugins[pluginId];
|
||||
// We are caching the import promises to prevent duplicate imports
|
||||
if (importPromises[pluginId] === undefined) {
|
||||
importPromises[pluginId] = doImportAppPlugin(meta);
|
||||
}
|
||||
|
||||
return importPromises[pluginId];
|
||||
}
|
||||
|
||||
async function doImportAppPlugin(meta: PluginMeta): Promise<AppPlugin> {
|
||||
throwIfAngular(meta);
|
||||
|
||||
const pluginExports = await importPluginModule({
|
||||
@ -214,24 +219,22 @@ export async function importAppPlugin(meta: PluginMeta): Promise<AppPlugin> {
|
||||
plugin.setComponentsFromLegacyExports(pluginExports);
|
||||
|
||||
exposedComponentsRegistry.register({
|
||||
pluginId,
|
||||
pluginId: meta.id,
|
||||
configs: plugin.exposedComponentConfigs || [],
|
||||
});
|
||||
addedComponentsRegistry.register({
|
||||
pluginId,
|
||||
pluginId: meta.id,
|
||||
configs: plugin.addedComponentConfigs || [],
|
||||
});
|
||||
addedLinksRegistry.register({
|
||||
pluginId,
|
||||
pluginId: meta.id,
|
||||
configs: plugin.addedLinkConfigs || [],
|
||||
});
|
||||
addedFunctionsRegistry.register({
|
||||
pluginId,
|
||||
pluginId: meta.id,
|
||||
configs: plugin.addedFunctionConfigs || [],
|
||||
});
|
||||
|
||||
importedAppPlugins[pluginId] = plugin;
|
||||
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user