From 1d69436b44f438716808846ef277e649a7864b28 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 3 Jan 2014 20:36:00 -0500 Subject: [PATCH] fix to getRecentReplies causing count = 0 to return unlimited --- src/categories.js | 4 ++++ src/routes/api.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/categories.js b/src/categories.js index b511ede803..29a4ce09f4 100644 --- a/src/categories.js +++ b/src/categories.js @@ -217,6 +217,10 @@ var db = require('./database.js'), }; Categories.getRecentReplies = function(cid, count, callback) { + if(count === 0) { + return callback(null, []); + } + db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) { if (err) { diff --git a/src/routes/api.js b/src/routes/api.js index 9555c4867f..85e74b71f2 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -55,9 +55,9 @@ var path = require('path'), }); function iterator(category, callback) { - categories.getRecentReplies(category.cid, category.numRecentTopics, function (err, posts) { + categories.getRecentReplies(category.cid, parseInt(category.numRecentTopics, 10), function (err, posts) { category.posts = posts; - category.post_count = posts.length > 2 ? 2 : posts.length; + category.post_count = posts.length > 2 ? 2 : posts.length; // this was a hack to make metro work back in the day, post_count should just = length callback(null); }); }