mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: db info page
if there is no connection to db, connect first
This commit is contained in:
@@ -201,11 +201,18 @@ mongoModule.checkCompatibilityVersion = function (version, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
mongoModule.info = function (db, callback) {
|
mongoModule.info = function (db, callback) {
|
||||||
if (!db) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
if (db) {
|
||||||
|
return setImmediate(next, null, db);
|
||||||
|
}
|
||||||
|
mongoModule.connect(nconf.get('mongo'), function (err, client) {
|
||||||
|
next(err, client ? client.db() : undefined);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (db, next) {
|
||||||
|
mongoModule.client = mongoModule.client || db;
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
serverStatus: function (next) {
|
serverStatus: function (next) {
|
||||||
db.command({ serverStatus: 1 }, next);
|
db.command({ serverStatus: 1 }, next);
|
||||||
|
|||||||
@@ -450,19 +450,26 @@ postgresModule.checkCompatibilityVersion = function (version, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
postgresModule.info = function (db, callback) {
|
postgresModule.info = function (db, callback) {
|
||||||
if (!db) {
|
async.waterfall([
|
||||||
return callback();
|
function (next) {
|
||||||
}
|
if (db) {
|
||||||
|
setImmediate(next, null, db);
|
||||||
|
} else {
|
||||||
|
postgresModule.connect(nconf.get('postgres'), next);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (db, next) {
|
||||||
|
postgresModule.pool = postgresModule.pool || db;
|
||||||
|
|
||||||
db.query(`
|
db.query(`
|
||||||
SELECT true "postgres",
|
SELECT true "postgres",
|
||||||
current_setting('server_version') "version",
|
current_setting('server_version') "version",
|
||||||
EXTRACT(EPOCH FROM NOW() - pg_postmaster_start_time()) * 1000 "uptime"`, function (err, res) {
|
EXTRACT(EPOCH FROM NOW() - pg_postmaster_start_time()) * 1000 "uptime"`, next);
|
||||||
if (err) {
|
},
|
||||||
return callback(err);
|
function (res, next) {
|
||||||
}
|
next(null, res.rows[0]);
|
||||||
callback(null, res.rows[0]);
|
},
|
||||||
});
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
postgresModule.close = function (callback) {
|
postgresModule.close = function (callback) {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ redisModule.connect = function (options, callback) {
|
|||||||
cxn.on('ready', function () {
|
cxn.on('ready', function () {
|
||||||
if (!callbackCalled) {
|
if (!callbackCalled) {
|
||||||
callbackCalled = true;
|
callbackCalled = true;
|
||||||
callback();
|
callback(null, cxn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -163,11 +163,16 @@ redisModule.close = function (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
redisModule.info = function (cxn, callback) {
|
redisModule.info = function (cxn, callback) {
|
||||||
if (!cxn) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
if (cxn) {
|
||||||
|
return setImmediate(next, null, cxn);
|
||||||
|
}
|
||||||
|
redisModule.connect(nconf.get('redis'), next);
|
||||||
|
},
|
||||||
|
function (cxn, next) {
|
||||||
|
redisModule.client = redisModule.client || cxn;
|
||||||
|
|
||||||
cxn.info(next);
|
cxn.info(next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ describe('Test database', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not error and return null if client is falsy', function (done) {
|
it('should not error and return info if client is falsy', function (done) {
|
||||||
db.info(null, function (err, info) {
|
db.info(null, function (err, info) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(info, null);
|
assert(info);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user