From 6514504dddcc22147287d04ca115519e2077f832 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 27 Jan 2014 09:09:55 -0500 Subject: [PATCH] fixed #889 --- src/categories.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/categories.js b/src/categories.js index 31e425c27b..85849b6523 100644 --- a/src/categories.js +++ b/src/categories.js @@ -136,16 +136,23 @@ var db = require('./database'), topics.getTopicsByTids(tids, cid, uid, next); }, function(topics, next) { - db.sortedSetRevRank('categories:' + cid + ':tid', topics[topics.length - 1].tid, function(err, rank) { - if(err) { - return next(err); - } + if (topics && topics.length > 0) { + db.sortedSetRevRank('categories:' + cid + ':tid', topics[topics.length - 1].tid, function(err, rank) { + if(err) { + return next(err); + } - return next(null, { + next(null, { + topics: topics, + nextStart: parseInt(rank, 10) + 1 + }); + }); + } else { + next(null, { topics: topics, - nextStart: parseInt(rank, 10) + 1 + nextStart: 1 }); - }); + } } ], callback); };