mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
Merge branch 'redis-optimizations' of https://github.com/adarqui/NodeBB into adarqui-redis-optimizations
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"socket.io": "~0.9.16",
|
"socket.io": "~0.9.16",
|
||||||
"redis": "0.8.3",
|
"redis": "0.8.3",
|
||||||
|
"hiredis" : "~0.1.15",
|
||||||
"express": "3.2.0",
|
"express": "3.2.0",
|
||||||
"express-namespace": "~0.1.1",
|
"express-namespace": "~0.1.1",
|
||||||
"emailjs": "0.3.4",
|
"emailjs": "0.3.4",
|
||||||
|
|||||||
56
src/posts.js
56
src/posts.js
@@ -153,7 +153,61 @@ var RDB = require('./redis.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* getPostsByPids using redis's multi pipeline */
|
||||||
Posts.getPostsByPids = function(pids, callback) {
|
Posts.getPostsByPids = function(pids, callback) {
|
||||||
|
var posts = []
|
||||||
|
var multi = RDB.multi();
|
||||||
|
|
||||||
|
for (v in pids) {
|
||||||
|
var _pid = pids[v]
|
||||||
|
multi.hgetall("post:"+_pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
multi.exec(function (err, replies) {
|
||||||
|
async.eachSeries(replies, function(postData, _callback) {
|
||||||
|
if(postData) {
|
||||||
|
postData.relativeTime = utils.relativeTime(postData.timestamp);
|
||||||
|
postData.post_rep = postData.reputation;
|
||||||
|
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
|
||||||
|
postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime (postData.edited) : '';
|
||||||
|
|
||||||
|
if(postData.uploadedImages) {
|
||||||
|
try {
|
||||||
|
postData.uploadedImages = JSON.parse(postData.uploadedImages);
|
||||||
|
} catch(err) {
|
||||||
|
postData.uploadedImages = [];
|
||||||
|
winston.err(err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
postData.uploadedImages = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
postTools.toHTML(postData.content, function(err, content) {
|
||||||
|
postData.content = content;
|
||||||
|
posts.push(postData);
|
||||||
|
});
|
||||||
|
return _callback(null)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return _callback(null)
|
||||||
|
}
|
||||||
|
}, function(err) {
|
||||||
|
if(!err) {
|
||||||
|
return callback(null, posts);
|
||||||
|
} else {
|
||||||
|
return callback(err, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Posts.getPostsByPids_original = function(pids, callback) {
|
||||||
var posts = [];
|
var posts = [];
|
||||||
|
|
||||||
async.eachSeries(pids, function(pid, callback) {
|
async.eachSeries(pids, function(pid, callback) {
|
||||||
@@ -432,4 +486,4 @@ var RDB = require('./redis.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|||||||
12
src/redis.js
12
src/redis.js
@@ -4,7 +4,15 @@
|
|||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
nconf = require('nconf');
|
nconf = require('nconf');
|
||||||
|
|
||||||
RedisDB.exports = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
|
var redis_socket_or_host = nconf.get('redis:host')
|
||||||
|
if(redis_socket_or_host.indexOf('/')>=0) {
|
||||||
|
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
|
||||||
|
RedisDB.exports = redis.createClient(nconf.get('redis:host'))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Else, connect over tcp/ip */
|
||||||
|
RedisDB.exports = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
|
||||||
|
}
|
||||||
|
|
||||||
if (nconf.get('redis:password')) {
|
if (nconf.get('redis:password')) {
|
||||||
RedisDB.exports.auth(nconf.get('redis:password'));
|
RedisDB.exports.auth(nconf.get('redis:password'));
|
||||||
@@ -55,4 +63,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
}(module));
|
}(module));
|
||||||
|
|||||||
Reference in New Issue
Block a user