Skip to content

Commit aeb5560

Browse files
committed
perf: Only copy scripts on plugin change and do not check the versions on every run
1 parent fe951dc commit aeb5560

8 files changed

Lines changed: 31 additions & 15 deletions

File tree

hooks/lando-copy-v3-scripts.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ module.exports = async lando => {
77
return lando.Promise.map(lando.config.plugins, plugin => {
88
if (fs.existsSync(plugin.scripts)) {
99
const confDir = path.join(lando.config.userConfRoot, 'scripts');
10-
const dest = require('../utils/move-config')(plugin.scripts, confDir);
11-
require('../utils/make-executable')(fs.readdirSync(dest), dest);
10+
require('../utils/move-config')(plugin.scripts, confDir);
1211
lando.log.debug('automoved scripts from %s to %s and set to mode 755', plugin.scripts, confDir);
1312
}
1413
});

hooks/lando-get-compat.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ const _ = require('lodash');
55
module.exports = async lando => {
66
// only run if engine bootstrap or above and if engine/orchestrator have been installed
77
if (lando._bootstrapLevel >= 3) {
8-
if (lando.engine.composeInstalled && lando.engine.dockerInstalled ) {
8+
if (lando.engine.composeInstalled && lando.engine.dockerInstalled) {
9+
if (!await lando.cache.isOlderThanMinutes('versions')) {
10+
return;
11+
}
12+
913
lando.engine.getCompatibility().then(results => {
1014
lando.log.verbose('checking docker version compatibility...');
1115
lando.log.debug('compatibility results', _.keyBy(results, 'name'));
12-
lando.cache.set('versions', _.assign(lando.versions, _.keyBy(results, 'name')), {persist: true});
16+
const lastLandoVersions = _.cloneDeep(lando.versions);
17+
_.assign(lando.versions, _.keyBy(results, 'name'));
18+
if (_.isEqual(lando.versions, lastLandoVersions)) {
19+
return;
20+
}
21+
lando.cache.set('versions', lando.versions, {persist: true});
1322
lando.versions = lando.cache.get('versions');
1423
});
1524
}

index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = async lando => {
8181
lando.events.once('pre-install-plugins', async options => await require('./hooks/lando-setup-common-plugins')(lando, options));
8282

8383
// move v3 scripts directories as needed
84-
lando.events.on('pre-setup', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));
84+
lando.events.on('post-install-plugins', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));
8585

8686
// ensure we setup docker if needed
8787
lando.events.once('pre-setup', async options => await require(`./hooks/lando-setup-build-engine-${platform}`)(lando, options));
@@ -100,12 +100,6 @@ module.exports = async lando => {
100100
// ensure we setup landonet
101101
lando.events.once('pre-setup', async options => await require('./hooks/lando-setup-landonet')(lando, options));
102102

103-
// also move scripts for init considerations
104-
lando.events.on('pre-init', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));
105-
106-
// move v3 scripts directories as needed
107-
lando.events.on('pre-init', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));
108-
109103
// set proxy config
110104
lando.events.on('post-bootstrap-config', async () => await require('./hooks/lando-set-proxy-config')(lando));
111105

@@ -131,9 +125,6 @@ module.exports = async lando => {
131125
// autostart docker if we need to
132126
lando.events.once('engine-autostart', async () => await require('./hooks/lando-autostart-engine')(lando));
133127

134-
// move v3 scripts directories as needed
135-
lando.events.on('pre-engine-start', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));
136-
137128
// clean networks
138129
lando.events.on('pre-engine-start', 1, async () => await require('./hooks/lando-clean-networks')(lando));
139130

lib/cache.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ class Cache extends NodeCache {
118118
this.log.debug('No file cache with key %s', key);
119119
}
120120
}
121+
122+
async isOlderThanMinutes(key, minutes = 5) {
123+
try {
124+
const stats = await fs.stat(path.join(this.cacheDir, key));
125+
const modifiedTime = stats.mtime;
126+
const minutesAgo = Date.now() - minutes * 60 * 1000;
127+
128+
return modifiedTime.getTime() < minutesAgo;
129+
} catch (err) {
130+
return false;
131+
}
132+
}
121133
}
122134

123135
/*

lib/daemon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ module.exports = class LandoDaemon {
223223

224224
// Return true if we get a zero response and cache the result
225225
try {
226-
await require('../utils/run-command')(docker, ['ps'], {debug: this.debug});
226+
await require('../utils/run-command')(docker, ['ps', '-q'], {debug: this.debug});
227227
this.debug('engine is up.');
228228
cache.set('engineup', true, {ttl: 5});
229229
this.isRunning = true;

tasks/plugin-add.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ module.exports = lando => {
8484
},
8585
});
8686

87+
await lando.events.emit('post-install-plugins', {errors, results, total});
88+
8789
// status
8890
console.log();
8991
console.log('added %s of %s plugins with %s errors', results.length, total, errors.length); // eslint-disable-line max-len

tasks/plugin-remove.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module.exports = lando => {
3939
},
4040
});
4141

42+
await lando.events.emit('post-install-plugins', {errors, results, total});
43+
4244
// otherwise we good!
4345
console.log();
4446
console.log('removed %s of %s plugins with %s errors', results.length, total, errors.length); // eslint-disable-line max-len

tasks/update.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ module.exports = lando => {
157157
},
158158
});
159159

160+
await lando.events.emit('post-install-plugins', {errors, results});
160161
// flush relevant caches
161162
lando.cli.clearTaskCaches();
162163
lando.cache.remove('updates-2');

0 commit comments

Comments
 (0)