moving db.close into the parent module

v1.18.x
psychobunny 11 years ago
parent df5f3d185a
commit bba3df6802

@ -38,14 +38,14 @@
winston.error('Unable to initialize Level DB! Is Level DB installed? Error :' + err.message); winston.error('Unable to initialize Level DB! Is Level DB installed? Error :' + err.message);
process.exit(); process.exit();
} }
if (db) { if (db) {
if(typeof callback === 'function') { if(typeof callback === 'function') {
callback(); callback();
} }
return; return;
} }
db = levelup(nconf.get('level:database'), { db = levelup(nconf.get('level:database'), {
valueEncoding: 'json' valueEncoding: 'json'
@ -77,6 +77,10 @@
} }
}; };
module.close = function(callback) {
db.close(callback);
};
var helpers = {}; var helpers = {};
helpers.iterator = function(fn, keys, value, callback) { helpers.iterator = function(fn, keys, value, callback) {

@ -5,10 +5,6 @@ var nconf = require('nconf'),
module.exports = function(db, module) { module.exports = function(db, module) {
var helpers = module.helpers.level; var helpers = module.helpers.level;
module.close = function(callback) {
db.close(callback);
};
module.searchIndex = function(key, content, id) { module.searchIndex = function(key, content, id) {
// o.O // o.O

@ -45,7 +45,7 @@
winston.error('Unable to initialize MongoDB! Is MongoDB installed? Error :' + err.message); winston.error('Unable to initialize MongoDB! Is MongoDB installed? Error :' + err.message);
process.exit(); process.exit();
} }
mongoClient.connect('mongodb://'+ nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) { mongoClient.connect('mongodb://'+ nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
if(err) { if(err) {
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
@ -105,6 +105,11 @@
}); });
}; };
module.close = function() {
db.close();
};
var helpers = {}; var helpers = {};
helpers.findItem = function(data, key) { helpers.findItem = function(data, key) {
if(!data) { if(!data) {

@ -4,10 +4,7 @@ var winston = require('winston');
module.exports = function(db, module) { module.exports = function(db, module) {
var helpers = module.helpers.mongo; var helpers = module.helpers.mongo;
module.close = function() {
db.close();
};
module.searchIndex = function(key, content, id) { module.searchIndex = function(key, content, id) {
var data = { var data = {

@ -101,5 +101,10 @@
callback(); callback();
} }
}; };
module.close = function() {
redisClient.quit();
};
}(exports)); }(exports));

@ -1,10 +1,6 @@
"use strict"; "use strict";
module.exports = function(redisClient, module) { module.exports = function(redisClient, module) {
module.close = function() {
redisClient.quit();
};
module.searchIndex = function(key, content, id) { module.searchIndex = function(key, content, id) {
if (key === 'post') { if (key === 'post') {
module.postSearch.index(content, id); module.postSearch.index(content, id);

Loading…
Cancel
Save