Skip to content
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

fix: exponential growth of plugin registry in App.init() #84

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ const initAndReport = (app, method = 'start') => {
/*
* Helper to load in all app plugins
*/
const loadPlugins = (app, lando) => Promise.resolve(app.plugins.registry)
// Filter out
.filter(plugin => _.has(plugin, 'app'))
// LOADEM!
.map(plugin => app.plugins.load(plugin, plugin.app, app, lando))
// Remove any naughty shit
.map(plugin => _.pick(plugin.data, ['config', 'composeData', 'env', 'labels']))
// Merge minotaur
.each(result => _.merge(app, result));
const loadPlugins = (app, lando) => {
app.appPlugins = [];
return Promise.resolve(app.plugins.registry)
// Filter out
.filter(plugin => _.has(plugin, 'app'))
// LOADEM!
.map(plugin => app.plugins.load(plugin, plugin.app, app, lando))
// Remove any naughty shit
.map(plugin => {
app.appPlugins.push(plugin);
return _.pick(plugin.data, ['config', 'composeData', 'env', 'labels']);
})
// Merge minotaur
.each(result => _.merge(app, result));
};

/**
* The class to instantiate a new App
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ class AsyncEvents extends EventEmitter {
};

// Set our maxListeners to something more reasonable for lando
AsyncEvents.prototype.setMaxListeners(Infinity);
AsyncEvents.prototype.setMaxListeners(128);

module.exports = AsyncEvents;
8 changes: 5 additions & 3 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ module.exports = class Plugins {
}

// Register, log, return
this.registry.push(plugin);
this.log.debug('plugin %s loaded from %s', plugin.name, file);
this.log.silly('plugin %s has', plugin.name, plugin.data);
if (!this.registry.find(p => p.name === plugin.name)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be further optimized so that we don't do this O(n) find but I guess it's good enough :)

this.registry.push(plugin);
this.log.debug('plugin %s loaded from %s', plugin.name, file);
this.log.silly('plugin %s has', plugin.name, plugin.data);
}
return plugin;
};
};
Loading