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) {
|
||||
if (!db) {
|
||||
return callback();
|
||||
}
|
||||
async.waterfall([
|
||||
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({
|
||||
serverStatus: function (next) {
|
||||
db.command({ serverStatus: 1 }, next);
|
||||
|
||||
@@ -450,19 +450,26 @@ postgresModule.checkCompatibilityVersion = function (version, callback) {
|
||||
};
|
||||
|
||||
postgresModule.info = function (db, callback) {
|
||||
if (!db) {
|
||||
return callback();
|
||||
async.waterfall([
|
||||
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(`
|
||||
SELECT true "postgres",
|
||||
current_setting('server_version') "version",
|
||||
EXTRACT(EPOCH FROM NOW() - pg_postmaster_start_time()) * 1000 "uptime"`, function (err, res) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, res.rows[0]);
|
||||
});
|
||||
EXTRACT(EPOCH FROM NOW() - pg_postmaster_start_time()) * 1000 "uptime"`, next);
|
||||
},
|
||||
function (res, next) {
|
||||
next(null, res.rows[0]);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
postgresModule.close = function (callback) {
|
||||
|
||||
@@ -98,7 +98,7 @@ redisModule.connect = function (options, callback) {
|
||||
cxn.on('ready', function () {
|
||||
if (!callbackCalled) {
|
||||
callbackCalled = true;
|
||||
callback();
|
||||
callback(null, cxn);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -163,11 +163,16 @@ redisModule.close = function (callback) {
|
||||
};
|
||||
|
||||
redisModule.info = function (cxn, callback) {
|
||||
if (!cxn) {
|
||||
return callback();
|
||||
}
|
||||
async.waterfall([
|
||||
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);
|
||||
},
|
||||
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) {
|
||||
assert.ifError(err);
|
||||
assert.equal(info, null);
|
||||
assert(info);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user