From 2fc569715c28fe9f89fc0aa32b05eace234aa9c0 Mon Sep 17 00:00:00 2001 From: adarqui Date: Sat, 21 Sep 2013 15:26:52 -0400 Subject: [PATCH 1/5] hiredis & underscore packages --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d34cef3a13..9d6f462879 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "socket.io": "~0.9.16", "redis": "0.8.3", + "hiredis" : "*", "express": "3.2.0", "express-namespace": "0.1.1", "emailjs": "0.3.4", @@ -37,7 +38,8 @@ "nodebb-plugin-mentions": "~0.1.0", "nodebb-plugin-markdown": "~0.1.0", "rss": "~0.2.0", - "prompt": "~0.2.11" + "prompt": "~0.2.11", + "underscore" : "*" }, "bugs": { "url": "https://github.com/designcreateplay/NodeBB/issues" From 98cb2d4c17d9cbc7934169f8e1b22cebae0bf2bf Mon Sep 17 00:00:00 2001 From: adarqui Date: Sat, 21 Sep 2013 15:42:54 -0400 Subject: [PATCH 2/5] a little logic to allow nodebb to use a unix domain socket rather than tcp/ip. unix dom sock has less overhead/latency. --- src/redis.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/redis.js b/src/redis.js index 5413f58651..91bd583f85 100644 --- a/src/redis.js +++ b/src/redis.js @@ -4,7 +4,15 @@ winston = require('winston'), 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')) { RedisDB.exports.auth(nconf.get('redis:password')); @@ -55,4 +63,4 @@ -}(module)); \ No newline at end of file +}(module)); From e26cc798197d3d932d2cc4d840839fe3560d01ce Mon Sep 17 00:00:00 2001 From: adarqui Date: Sat, 21 Sep 2013 22:47:27 -0400 Subject: [PATCH 3/5] redis multi pipeline used for getPostsByPids --- src/posts.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/posts.js b/src/posts.js index dee76c0474..82c7ad30bb 100644 --- a/src/posts.js +++ b/src/posts.js @@ -153,7 +153,65 @@ var RDB = require('./redis.js'), } + + + /* getPostsByPids using redis's multi pipeline */ Posts.getPostsByPids = function(pids, callback) { + var posts = [] + var new_pids = [] + + var multi = RDB.multi(); + + for (v in pids) { + var _pid = pids[v] + multi.hgetall("post:"+_pid); + } + + multi.exec(function (err, replies) { + var pids = replies + async.eachSeries(pids, function(pid, _callback) { + var postData = pid + 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 = []; async.eachSeries(pids, function(pid, callback) { @@ -432,4 +490,4 @@ var RDB = require('./redis.js'), }); } -}(exports)); \ No newline at end of file +}(exports)); From d2b858c997ff95c263847f179542bc18e57ca990 Mon Sep 17 00:00:00 2001 From: Andrew Darqui Date: Sun, 22 Sep 2013 00:36:40 -0400 Subject: [PATCH 4/5] slight variable name changes & remove unused var from getPostsByPids, removed underscore dependency --- src/posts.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/posts.js b/src/posts.js index 82c7ad30bb..c061adb55a 100644 --- a/src/posts.js +++ b/src/posts.js @@ -158,8 +158,6 @@ var RDB = require('./redis.js'), /* getPostsByPids using redis's multi pipeline */ Posts.getPostsByPids = function(pids, callback) { var posts = [] - var new_pids = [] - var multi = RDB.multi(); for (v in pids) { @@ -168,9 +166,7 @@ var RDB = require('./redis.js'), } multi.exec(function (err, replies) { - var pids = replies - async.eachSeries(pids, function(pid, _callback) { - var postData = pid + async.eachSeries(replies, function(postData, _callback) { if(postData) { postData.relativeTime = utils.relativeTime(postData.timestamp); postData.post_rep = postData.reputation; From d3e37d1716047ac5175a4327eb3c9bac24ec35b8 Mon Sep 17 00:00:00 2001 From: Andrew Darqui Date: Sun, 22 Sep 2013 00:36:56 -0400 Subject: [PATCH 5/5] slight variable name changes & remove unused var from getPostsByPids, removed underscore dependency --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9d6f462879..0ef89d1e9c 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dependencies": { "socket.io": "~0.9.16", "redis": "0.8.3", - "hiredis" : "*", + "hiredis" : "~0.1.15", "express": "3.2.0", "express-namespace": "0.1.1", "emailjs": "0.3.4", @@ -38,8 +38,7 @@ "nodebb-plugin-mentions": "~0.1.0", "nodebb-plugin-markdown": "~0.1.0", "rss": "~0.2.0", - "prompt": "~0.2.11", - "underscore" : "*" + "prompt": "~0.2.11" }, "bugs": { "url": "https://github.com/designcreateplay/NodeBB/issues"