Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit fcb44ae256

@ -1,3 +1,6 @@
'use strict';
var db = require('./database'),
posts = require('./posts'),
utils = require('./../public/src/utils'),
@ -13,7 +16,6 @@ var db = require('./database'),
nconf = require('nconf');
(function(Categories) {
"use strict";
Categories.create = function(data, callback) {
db.incrObjectField('global', 'nextCid', function(err, cid) {
@ -161,11 +163,11 @@ var db = require('./database'),
Categories.getAllCategories = function(uid, callback) {
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
if(err) {
if (err) {
return callback(err);
}
if(cids && cids.length === 0) {
if (!cids || (cids && cids.length === 0)) {
return callback(null, {categories : []});
}
@ -339,7 +341,6 @@ var db = require('./database'),
'categories': categories
});
});
};
Categories.isUserActiveIn = function(cid, uid, callback) {

@ -1,7 +1,8 @@
'use strict';
(function(module) {
'use strict';
var winston = require('winston'),
async = require('async'),
nconf = require('nconf'),
@ -68,15 +69,15 @@
});
if(typeof callback === 'function') {
callback(null);
callback();
}
}
});
}
};
module.close = function() {
db.close();
}
};
//
// helper functions
@ -129,7 +130,7 @@
winston.error('Error indexing ' + err.message);
}
});
}
};
module.search = function(key, term, limit, callback) {
db.command({text:"search" , search: term, filter: {key:key}, limit: limit }, function(err, result) {
@ -150,7 +151,7 @@
callback(null, []);
}
});
}
};
module.searchRemove = function(key, id, callback) {
db.collection('search').remove({id:id, key:key}, function(err, result) {
@ -161,27 +162,22 @@
callback();
}
});
}
};
module.flushdb = function(callback) {
db.dropDatabase(function(err, result) {
if(err){
winston.error(error);
if(typeof callback === 'function') {
if (err) {
winston.error(err.message);
if (typeof callback === 'function') {
return callback(err);
}
}
if(typeof callback === 'function') {
callback(null);
if (typeof callback === 'function') {
callback();
}
});
}
module.getFileName = function(callback) {
throw new Error('not-implemented');
}
};
module.info = function(callback) {
db.stats({scale:1024}, function(err, stats) {
@ -189,10 +185,6 @@
return callback(err);
}
// TODO : if this it not deleted the templates break,
// it is a nested object inside stats
delete stats.dataFileVersion;
stats.avgObjSize = (stats.avgObjSize / 1024).toFixed(2);
stats.raw = JSON.stringify(stats, null, 4);
@ -201,7 +193,7 @@
callback(null, stats);
});
}
};
// key
@ -209,7 +201,7 @@
db.collection('objects').findOne({_key:key}, function(err, item) {
callback(err, item !== undefined && item !== null);
});
}
};
module.delete = function(key, callback) {
db.collection('objects').remove({_key:key}, function(err, result) {
@ -217,22 +209,22 @@
callback(err, result);
}
});
}
};
module.get = function(key, callback) {
module.getObjectField(key, 'value', callback);
}
};
module.set = function(key, value, callback) {
var data = {value:value};
module.setObject(key, data, callback);
}
};
module.keys = function(key, callback) {
db.collection('objects').find( { _key: { $regex: key /*, $options: 'i'*/ } }, function(err, result) {
callback(err, result);
});
}
};
module.rename = function(oldKey, newKey, callback) {
db.collection('objects').update({_key: oldKey}, {$set:{_key: newKey}}, function(err, result) {
@ -240,25 +232,25 @@
callback(err, result);
}
});
}
};
module.expire = function(key, seconds, callback) {
module.expireAt(key, Math.round(Date.now() / 1000) + seconds, callback);
}
};
module.expireAt = function(key, timestamp, callback) {
module.setObjectField(key, 'expireAt', new Date(timestamp * 1000), callback);
}
};
//hashes
module.setObject = function(key, data, callback) {
data['_key'] = key;
data._key = key;
db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) {
if(typeof callback === 'function') {
callback(err, result);
}
});
}
};
module.setObjectField = function(key, field, value, callback) {
var data = {};
@ -273,7 +265,7 @@
callback(err, result);
}
});
}
};
module.getObject = function(key, callback) {
db.collection('objects').findOne({_key:key}, function(err, item) {
@ -281,7 +273,7 @@
callback(err, item);
});
}
};
module.getObjects = function(keys, callback) {
@ -299,7 +291,7 @@
callback(null, returnData);
});
}
};
module.getObjectField = function(key, field, callback) {
module.getObjectFields(key, [field], function(err, data) {
@ -309,7 +301,7 @@
callback(null, data[field]);
});
}
};
module.getObjectFields = function(key, fields, callback) {
@ -342,7 +334,7 @@
callback(null, item);
});
}
};
module.getObjectKeys = function(key, callback) {
module.getObject(key, function(err, data) {
@ -356,7 +348,7 @@
callback(null, []);
}
});
}
};
module.getObjectValues = function(key, callback) {
module.getObject(key, function(err, data) {
@ -370,7 +362,7 @@
}
callback(null, values);
});
}
};
module.isObjectField = function(key, field, callback) {
var data = {};
@ -385,7 +377,7 @@
}
callback(err, !!item && item[field] !== undefined && item[field] !== null);
});
}
};
module.deleteObjectField = function(key, field, callback) {
var data = {};
@ -399,15 +391,15 @@
callback(err, result);
}
});
}
};
module.incrObjectField = function(key, field, callback) {
module.incrObjectFieldBy(key, field, 1, callback);
}
};
module.decrObjectField = function(key, field, callback) {
module.incrObjectFieldBy(key, field, -1, callback);
}
};
module.incrObjectFieldBy = function(key, field, value, callback) {
var data = {};
@ -422,7 +414,7 @@
callback(err, result ? result[field] : null);
}
});
}
};
// sets
@ -437,19 +429,12 @@
});
db.collection('objects').update({_key:key},
{
$addToSet: { members: { $each: value } }
},
{
upsert:true, w: 1
}
, function(err, result) {
db.collection('objects').update({_key: key}, { $addToSet: { members: { $each: value } } }, { upsert: true, w: 1 }, function(err, result) {
if(typeof callback === 'function') {
callback(err, result);
}
});
}
};
module.setRemove = function(key, value, callback) {
if(!Array.isArray(value)) {
@ -465,7 +450,7 @@
callback(err, result);
}
});
}
};
module.isSetMember = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -475,7 +460,7 @@
db.collection('objects').findOne({_key:key, members: value}, function(err, item) {
callback(err, item !== null && item !== undefined);
});
}
};
module.isMemberOfSets = function(sets, value, callback) {
@ -498,7 +483,7 @@
callback(err, result);
});
}
};
module.getSetMembers = function(key, callback) {
db.collection('objects').findOne({_key:key}, {members:1}, function(err, data) {
@ -512,7 +497,7 @@
callback(null, data.members);
}
});
}
};
module.setCount = function(key, callback) {
db.collection('objects').findOne({_key:key}, function(err, data) {
@ -525,7 +510,7 @@
callback(null, data.members.length);
});
}
};
module.setRemoveRandom = function(key, callback) {
db.collection('objects').findOne({_key:key}, function(err, data) {
@ -551,7 +536,7 @@
});
}
});
}
};
// sorted sets
@ -570,7 +555,7 @@
callback(err, result);
}
});
}
};
module.sortedSetRemove = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -582,7 +567,7 @@
callback(err, result);
}
});
}
};
function getSortedSetRange(key, start, stop, sort, callback) {
db.collection('objects').find({_key:key}, {fields:{value:1}})
@ -590,26 +575,29 @@
.skip(start)
.sort({score: sort})
.toArray(function(err, data) {
if(err) {
if (err) {
return callback(err);
}
// maybe this can be done with mongo?
if (!data) {
return callback(null, null);
}
data = data.map(function(item) {
return item.value;
});
callback(err, data);
callback(null, data);
});
}
module.getSortedSetRange = function(key, start, stop, callback) {
getSortedSetRange(key, start, stop, 1, callback);
}
};
module.getSortedSetRevRange = function(key, start, stop, callback) {
getSortedSetRange(key, start, stop, -1, callback);
}
};
module.getSortedSetRevRangeByScore = function(args, callback) {
@ -640,7 +628,7 @@
callback(err, data);
});
}
};
module.sortedSetCount = function(key, min, max, callback) {
db.collection('objects').count({_key:key, score: {$gte:min, $lte:max}}, function(err, count) {
@ -653,7 +641,7 @@
}
callback(null,count);
});
}
};
module.sortedSetCard = function(key, callback) {
db.collection('objects').count({_key:key}, function(err, count) {
@ -666,7 +654,7 @@
}
callback(null, count);
});
}
};
module.sortedSetRank = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -683,7 +671,7 @@
callback(null, rank);
});
}
};
module.sortedSetRevRank = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -702,7 +690,7 @@
callback(null, rank);
});
}
};
module.sortedSetScore = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -718,13 +706,13 @@
callback(err, null);
});
}
};
module.isSortedSetMember = function(key, value, callback) {
module.sortedSetScore(key, value, function(err, score) {
callback(err, !!score);
});
}
};
module.sortedSetsScore = function(keys, value, callback) {
if(value !== null && value !== undefined) {
@ -745,13 +733,14 @@
callback(null, returnData);
});
}
};
// lists
module.listPrepend = function(key, value, callback) {
if(value !== null && value !== undefined) {
value = value.toString();
}
module.isObjectField(key, 'array', function(err, exists) {
if(err) {
if(typeof callback === 'function') {
@ -762,17 +751,16 @@
}
if(exists) {
db.collection('objects').update({_key:key}, {'$set': {'array.-1': value}}, {upsert:true, w:1 }, function(err, result) {
db.collection('objects').update({_key:key}, {'$set': {'array.-1': value}}, {upsert:true, w:1 }, function(err, result) {
if(typeof callback === 'function') {
callback(err, result);
}
});
} else {
module.listAppend(key, value, callback);
}
})
}
});
} else {
module.listAppend(key, value, callback);
}
});
};
module.listAppend = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -783,7 +771,7 @@
callback(err, result);
}
});
}
};
module.listRemoveLast = function(key, callback) {
module.getListRange(key, -1, 0, function(err, value) {
@ -808,7 +796,7 @@
}
});
});
}
};
module.listRemoveAll = function(key, value, callback) {
if(value !== null && value !== undefined) {
@ -820,7 +808,7 @@
callback(err, result);
}
});
}
};
module.getListRange = function(key, start, stop, callback) {
@ -867,8 +855,7 @@
callback(null, []);
}
});
}
};
}(exports));

@ -11,7 +11,9 @@
redis,
connectRedis,
reds,
redisClient;
redisClient,
postSearch,
topicSearch;
try {
redis = require('redis');
@ -22,54 +24,52 @@
process.exit();
}
module.init = function(callback) {
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
redisClient = redis.createClient(nconf.get('redis:host'));
} else {
/* Else, connect over tcp/ip */
redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
}
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
redisClient = redis.createClient(nconf.get('redis:host'));
} else {
/* Else, connect over tcp/ip */
redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
}
if (nconf.get('redis:password')) {
redisClient.auth(nconf.get('redis:password'));
} else {
winston.warn('You have no redis password setup!');
}
redisClient.on('error', function (err) {
winston.error(err.message);
process.exit();
});
if (nconf.get('redis:password')) {
redisClient.auth(nconf.get('redis:password'));
} else {
winston.warn('You have no redis password setup!');
}
redisClient.on('error', function (err) {
winston.error(err.message);
process.exit();
});
module.client = redisClient;
module.client = redisClient;
module.sessionStore = new connectRedis({
client: redisClient,
ttl: 60 * 60 * 24 * 14
});
module.sessionStore = new connectRedis({
client: redisClient,
ttl: 60 * 60 * 24 * 14
});
reds.createClient = function () {
return reds.client || (reds.client = redisClient);
};
reds.createClient = function () {
return reds.client || (reds.client = redisClient);
};
var postSearch = reds.createSearch('nodebbpostsearch'),
postSearch = reds.createSearch('nodebbpostsearch'),
topicSearch = reds.createSearch('nodebbtopicsearch');
var db = parseInt(nconf.get('redis:database'), 10);
var db = parseInt(nconf.get('redis:database'), 10);
if (db) {
redisClient.select(db, function(error) {
if(error) {
winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message);
process.exit();
}
});
}
if (db) {
redisClient.select(db, function(error) {
if(error) {
winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message);
process.exit();
}
});
}
module.init = function(callback) {
callback(null);
callback();
};
module.close = function() {
@ -125,26 +125,6 @@
});
};
module.getFileName = function(callback) {
var multi = redisClient.multi();
multi.config('get', 'dir');
multi.config('get', 'dbfilename');
multi.exec(function (err, results) {
if (err) {
return callback(err);
}
results = results.reduce(function (memo, config) {
memo[config[0]] = config[1];
return memo;
}, {});
var dbFile = path.join(results.dir, results.dbfilename);
callback(null, dbFile);
});
};
module.info = function(callback) {
redisClient.info(function (err, data) {
if(err) {

@ -297,12 +297,6 @@ var fs = require('fs'),
}
};
Meta.db = {
getFile: function (callback) {
db.getFileName(callback);
}
};
Meta.css = {
cache: undefined
};

@ -347,28 +347,6 @@ var nconf = require('nconf'),
res.json(data);
});
});
// app.get('/export', function (req, res) {
// meta.db.getFile(function (err, dbFile) {
// if (!err) {
// res.download(dbFile, 'redis.rdb', function (err) {
// console.log(err);
// res.send(500);
// if (err) {
// res.send(500);
// switch (err.code) {
// case 'EACCES':
// res.send(500, 'Require permissions from Redis database file: ', dbFile);
// break;
// default:
// res.send(500);
// break;
// }
// }
// });
// } else res.send(500);
// });
// });
});
app.get('/events', function(req, res, next) {

Loading…
Cancel
Save