Skip to content

Commit

Permalink
fix: exponential growth of plugin registry in App.init()
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Sep 10, 2024
1 parent 3ecb5d6 commit 5f17768
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
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)) {
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;
};
};

0 comments on commit 5f17768

Please sign in to comment.