mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
fixing issue where NodeBB hangs if a non-existant topic was requested
This commit is contained in:
@@ -29,7 +29,9 @@
|
|||||||
Feed.updateTopic = function(tid, cid) {
|
Feed.updateTopic = function(tid, cid) {
|
||||||
var cache_time_in_seconds = 60;
|
var cache_time_in_seconds = 60;
|
||||||
|
|
||||||
topics.getTopicWithPosts(tid, 0, function(topicData) {
|
topics.getTopicWithPosts(tid, 0, function(err, topicData) {
|
||||||
|
if (err) console.log('Error: Problem saving topic RSS feed', err);
|
||||||
|
|
||||||
var location = '/topic/' + topicData.slug,
|
var location = '/topic/' + topicData.slug,
|
||||||
xml_url = '/topic/' + tid + '.rss';
|
xml_url = '/topic/' + tid + '.rss';
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,13 @@ var RDB = require('./redis.js'),
|
|||||||
notifications = require('./notifications.js');
|
notifications = require('./notifications.js');
|
||||||
|
|
||||||
(function(ThreadTools) {
|
(function(ThreadTools) {
|
||||||
|
|
||||||
|
ThreadTools.exists = function(tid, callback) {
|
||||||
|
RDB.sismember('topics:tid', tid, function(err, ismember) {
|
||||||
|
if (err) RDB.handle(err);
|
||||||
|
callback(!!ismember || false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ThreadTools.privileges = function(tid, uid, callback) {
|
ThreadTools.privileges = function(tid, uid, callback) {
|
||||||
//todo: break early if one condition is true
|
//todo: break early if one condition is true
|
||||||
|
|||||||
@@ -84,47 +84,51 @@ marked.setOptions({
|
|||||||
}
|
}
|
||||||
|
|
||||||
Topics.getTopicWithPosts = function(tid, current_user, callback) {
|
Topics.getTopicWithPosts = function(tid, current_user, callback) {
|
||||||
|
threadTools.exists(tid, function(exists) {
|
||||||
Topics.markAsRead(tid, current_user);
|
if (!exists) return callback(new Error('Topic tid \'' + tid + '\' not found'));
|
||||||
|
|
||||||
function getTopicData(next) {
|
Topics.markAsRead(tid, current_user);
|
||||||
Topics.getTopicData(tid, function(topicData) {
|
|
||||||
next(null, topicData);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTopicPosts(next) {
|
function getTopicData(next) {
|
||||||
Topics.getTopicPosts(tid, 0, -1, current_user, function(topicPosts, privileges) {
|
Topics.getTopicData(tid, function(topicData) {
|
||||||
|
next(null, topicData);
|
||||||
next(null, topicPosts);
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function getPrivileges(next) {
|
function getTopicPosts(next) {
|
||||||
threadTools.privileges(tid, current_user, function(privData) {
|
Topics.getTopicPosts(tid, 0, -1, current_user, function(topicPosts, privileges) {
|
||||||
next(null, privData);
|
|
||||||
});
|
next(null, topicPosts);
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async.parallel([getTopicData, getTopicPosts, getPrivileges], function(err, results) {
|
function getPrivileges(next) {
|
||||||
var topicData = results[0],
|
threadTools.privileges(tid, current_user, function(privData) {
|
||||||
topicPosts = results[1],
|
next(null, privData);
|
||||||
privileges = results[2];
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var main_posts = topicPosts.splice(0, 1);
|
async.parallel([getTopicData, getTopicPosts, getPrivileges], function(err, results) {
|
||||||
|
if (err) console.log(err.message);
|
||||||
|
var topicData = results[0],
|
||||||
|
topicPosts = results[1],
|
||||||
|
privileges = results[2];
|
||||||
|
|
||||||
callback({
|
var main_posts = topicPosts.splice(0, 1);
|
||||||
'topic_name':topicData.title,
|
|
||||||
'category_name':topicData.category_name,
|
callback(null, {
|
||||||
'category_slug':topicData.category_slug,
|
'topic_name':topicData.title,
|
||||||
'locked': topicData.locked,
|
'category_name':topicData.category_name,
|
||||||
'deleted': topicData.deleted,
|
'category_slug':topicData.category_slug,
|
||||||
'pinned': topicData.pinned,
|
'locked': topicData.locked,
|
||||||
'slug': topicData.slug,
|
'deleted': topicData.deleted,
|
||||||
'topic_id': tid,
|
'pinned': topicData.pinned,
|
||||||
'expose_tools': privileges.editable ? 1 : 0,
|
'slug': topicData.slug,
|
||||||
'posts': topicPosts,
|
'topic_id': tid,
|
||||||
'main_posts': main_posts
|
'expose_tools': privileges.editable ? 1 : 0,
|
||||||
|
'posts': topicPosts,
|
||||||
|
'main_posts': main_posts
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,9 @@ var express = require('express'),
|
|||||||
|
|
||||||
|
|
||||||
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
|
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
|
||||||
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(topic) {
|
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {
|
||||||
|
if (err) return res.redirect('404');
|
||||||
|
|
||||||
res.send(
|
res.send(
|
||||||
app.build_header(res) +
|
app.build_header(res) +
|
||||||
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +
|
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +
|
||||||
@@ -238,7 +240,7 @@ var express = require('express'),
|
|||||||
res.json(data);
|
res.json(data);
|
||||||
break;
|
break;
|
||||||
case 'topic' :
|
case 'topic' :
|
||||||
topics.getTopicWithPosts(req.params.id, uid, function(data) {
|
topics.getTopicWithPosts(req.params.id, uid, function(err, data) {
|
||||||
res.json(data);
|
res.json(data);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user