From e979d1bf0db8bc7eed13f784784ad9d75f35d61a Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 8 Aug 2013 14:30:42 -0400 Subject: [PATCH] fixed home loading --- src/categories.js | 5 +++++ src/posts.js | 4 +++- src/routes/api.js | 9 +++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/categories.js b/src/categories.js index ce6e134fb3..4f584b077a 100644 --- a/src/categories.js +++ b/src/categories.js @@ -186,6 +186,11 @@ var RDB = require('./redis.js'), Categories.getRecentReplies = function(cid, count, callback) { RDB.zrevrange('categories:recent_posts:cid:' + cid, 0, (count<10)?10:count, function(err, pids) { + if(err) { + console.log(err); + callback([]); + return; + } if (pids.length == 0) { callback([]); diff --git a/src/posts.js b/src/posts.js index febaa8c16a..146ff06825 100644 --- a/src/posts.js +++ b/src/posts.js @@ -60,7 +60,7 @@ var RDB = require('./redis.js'), function getPostSummary(pid, callback) { Posts.getPostFields(pid, ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'], function(postData) { if(postData.deleted === '1') { - return; + return callback(null); } Posts.addUserInfoToPost(postData, function() { @@ -81,6 +81,8 @@ var RDB = require('./redis.js'), async.eachSeries(pids, getPostSummary, function(err) { if(!err) { callback(returnData); + } else { + console.log(err); } }); }; diff --git a/src/routes/api.js b/src/routes/api.js index 246265b1f9..1a4094cdde 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -17,7 +17,7 @@ var user = require('./../user.js'), app.get('/api/home', function(req, res) { var uid = (req.user) ? req.user.uid : 0; categories.getAllCategories(function(data) { - + data.categories = data.categories.filter(function(category) { return (!category.disabled || category.disabled === "0"); }); @@ -26,16 +26,17 @@ var user = require('./../user.js'), categories.getRecentReplies(category.cid, 2, function(posts) { category["posts"] = posts; category["post_count"] = posts.length>2 ? 2 : posts.length; + console.log(category.cid, 'worked'); callback(null); }); } - + require('async').each(data.categories, iterator, function(err) { data.motd_class = (config.show_motd === '1' || config.show_motd === undefined) ? '' : 'none'; data.motd = marked(config.motd || "# NodeBB v" + pkg.version + "\nWelcome to NodeBB, the discussion platform of the future.\n\n Get NodeBB Fork us on Github @dcplabs"); - res.json(data); + res.json(data); }); - + }, uid); });