Skip to content

Commit

Permalink
refactor(ssh): delay loading of tunnel-ssh and improve load time
Browse files Browse the repository at this point in the history
This improves the loadtime of db-migrate by 47%. To be exact from ~22ms to ~15ms.

Resolves #387
  • Loading branch information
wzrdtales committed Jul 15, 2016
1 parent 3fca510 commit 47b72fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ internals.mod.log = require('db-migrate-shared').log;
internals.mod.type = require('db-migrate-shared').dataType;
var Shadow = require('./shadow');
var log = internals.mod.log;
var tunnel = require('tunnel-ssh'),
Promise = require('bluebird'),
var Promise = require('bluebird'),
SeederInterface = require('../interface/seederInterface.js'),
MigratorInterface = require('../interface/migratorInterface.js'),
resolve = require( 'resolve' );
Expand Down Expand Up @@ -119,6 +118,7 @@ exports.connect = function (config, intern, callback) {
};

if (config.tunnel) {
var tunnel = require('tunnel-ssh');
var tunnelConfig = JSON.parse(JSON.stringify(config.tunnel));
tunnelConfig.dstHost = config.host;
tunnelConfig.dstPort = config.port;
Expand All @@ -132,7 +132,6 @@ exports.connect = function (config, intern, callback) {
config.port = tunnelConfig.localPort;

tunnel(tunnelConfig, function (err) {

if (err) {
callback(err);
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"pkginfo": "~0.3.0",
"resolve": "^1.1.6",
"semver": "~5.1.0",
"tunnel-ssh": "^2.0.0"
"tunnel-ssh": "^4.0.0"
},
"devDependencies": {
"code": "^1.3.0",
Expand Down

0 comments on commit 47b72fa

Please sign in to comment.