even more search changes

v1.18.x
barisusakli 10 years ago
parent 2b7744f905
commit 78c65aee05

@ -74,37 +74,29 @@ module.exports = function(Categories) {
}); });
}; };
Categories.onNewPostMade = function(postData, callback) { Categories.onNewPostMade = function(cid, pinned, postData, callback) {
topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) { if (!cid || !postData) {
if (err) { return callback();
return callback(err); }
}
if (!topicData || !topicData.cid) {
return callback();
}
var cid = topicData.cid;
async.parallel([ async.parallel([
function(next) { function(next) {
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next); db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);
}, },
function(next) { function(next) {
db.incrObjectField('category:' + cid, 'post_count', next); db.incrObjectField('category:' + cid, 'post_count', next);
}, },
function(next) { function(next) {
if (parseInt(topicData.pinned, 10) === 1) { if (parseInt(pinned, 10) === 1) {
next(); next();
} else { } else {
db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next); db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next);
}
},
function(next) {
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, next);
} }
], callback); },
}); function(next) {
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, next);
}
], callback);
}; };
}; };

@ -12,8 +12,8 @@ module.exports = function(db, module) {
key: key key: key
}; };
for(var field in data) { for(var field in data) {
if (data.hasOwnProperty(field)) { if (data.hasOwnProperty(field) && data[field]) {
setData[field] = data[field]; setData[field] = data[field].toString();
} }
} }

@ -19,7 +19,7 @@ var winston = require('winston'),
var cache = LRU({ var cache = LRU({
max: 1048576, max: 1048576,
length: function (n) { return n.length }, length: function (n) { return n.length; },
maxAge: 1000 * 60 * 60 maxAge: 1000 * 60 * 60
}); });
@ -63,22 +63,32 @@ var cache = LRU({
}, },
topic: function(next) { topic: function(next) {
var tid = postData.tid; var tid = postData.tid;
posts.isMain(data.pid, function(err, isMainPost) { async.parallel({
cid: function(next) {
topics.getTopicField(tid, 'cid', next);
},
isMain: function(next) {
posts.isMain(data.pid, next);
}
}, function(err, results) {
if (err) { if (err) {
return next(err); return next(err);
} }
options.tags = options.tags || []; options.tags = options.tags || [];
if (!isMainPost) { if (!results.isMain) {
return next(null, { return next(null, {
tid: tid, tid: tid,
cid: results.cid,
isMainPost: false isMainPost: false
}); });
} }
var topicData = { var topicData = {
tid: tid, tid: tid,
cid: results.cid,
uid: postData.uid,
mainPid: data.pid, mainPid: data.pid,
title: title, title: title,
slug: tid + '/' + utils.slugify(title) slug: tid + '/' + utils.slugify(title)
@ -98,8 +108,10 @@ var cache = LRU({
topics.getTopicTagsObjects(tid, function(err, tags) { topics.getTopicTagsObjects(tid, function(err, tags) {
next(err, { next(err, {
tid: tid, tid: tid,
cid: results.cid,
uid: postData.uid,
title: validator.escape(title), title: validator.escape(title),
isMainPost: isMainPost, isMainPost: results.isMain,
tags: tags tags: tags
}); });
}); });
@ -114,6 +126,7 @@ var cache = LRU({
if (err) { if (err) {
return callback(err); return callback(err);
} }
postData.cid = results.topic.cid;
results.content = results.postData.content; results.content = results.postData.content;
plugins.fireHook('action:post.edit', postData); plugins.fireHook('action:post.edit', postData);

@ -68,7 +68,13 @@ module.exports = function(Posts) {
topics.onNewPostMade(postData, next); topics.onNewPostMade(postData, next);
}, },
function(next) { function(next) {
categories.onNewPostMade(postData, next); topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) {
if (err) {
return next(err);
}
postData.cid = topicData.cid;
categories.onNewPostMade(topicData.cid, topicData.pinned, postData, next);
});
}, },
function(next) { function(next) {
db.sortedSetAdd('posts:pid', timestamp, postData.pid, next); db.sortedSetAdd('posts:pid', timestamp, postData.pid, next);

@ -9,16 +9,19 @@ var async = require('async'),
module.exports = function(Posts) { module.exports = function(Posts) {
Posts.delete = function(pid, callback) { Posts.delete = function(pid, callback) {
Posts.setPostField(pid, 'deleted', 1, function(err) { var postData;
if (err) { async.waterfall([
return callback(err); function(next) {
} Posts.setPostField(pid, 'deleted', 1, next);
},
Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'timestamp'], function(err, postData) { function(next) {
if (err) { Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'timestamp'], next);
return callback(err); },
} function(_post, next) {
postData = _post;
topics.getTopicField(_post.tid, 'cid', next);
},
function(cid, next) {
plugins.fireHook('action:post.delete', pid); plugins.fireHook('action:post.delete', pid);
async.parallel([ async.parallel([
@ -26,7 +29,7 @@ module.exports = function(Posts) {
updateTopicTimestamp(postData.tid, next); updateTopicTimestamp(postData.tid, next);
}, },
function(next) { function(next) {
removeFromCategoryRecentPosts(pid, postData.tid, next); db.sortedSetRemove('cid:' + cid + ':pids', pid, next);
}, },
function(next) { function(next) {
Posts.dismissFlag(pid, next); Posts.dismissFlag(pid, next);
@ -34,21 +37,25 @@ module.exports = function(Posts) {
], function(err) { ], function(err) {
callback(err, postData); callback(err, postData);
}); });
}); }
}); ], callback);
}; };
Posts.restore = function(pid, callback) { Posts.restore = function(pid, callback) {
Posts.setPostField(pid, 'deleted', 0, function(err) { var postData;
if (err) { async.waterfall([
return callback(err); function(next) {
} Posts.setPostField(pid, 'deleted', 0, next);
},
Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], function(err, postData) { function(next) {
if (err) { Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], next);
return callback(err); },
} function(_post, next) {
postData = _post;
topics.getTopicField(_post.tid, 'cid', next);
},
function(cid, next) {
postData.cid = cid;
plugins.fireHook('action:post.restore', postData); plugins.fireHook('action:post.restore', postData);
async.parallel([ async.parallel([
@ -56,13 +63,13 @@ module.exports = function(Posts) {
updateTopicTimestamp(postData.tid, next); updateTopicTimestamp(postData.tid, next);
}, },
function(next) { function(next) {
addToCategoryRecentPosts(pid, postData.tid, postData.timestamp, next); db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, pid, next);
} }
], function(err) { ], function(err) {
callback(err, postData); callback(err, postData);
}); });
}); }
}); ], callback);
}; };
function updateTopicTimestamp(tid, callback) { function updateTopicTimestamp(tid, callback) {
@ -84,26 +91,6 @@ module.exports = function(Posts) {
}); });
} }
function removeFromCategoryRecentPosts(pid, tid, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) {
if (err) {
return callback(err);
}
db.sortedSetRemove('cid:' + cid + ':pids', pid, callback);
});
}
function addToCategoryRecentPosts(pid, tid, timestamp, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) {
if (err) {
return callback(err);
}
db.sortedSetAdd('cid:' + cid + ':pids', timestamp, pid, callback);
});
}
Posts.purge = function(pid, callback) { Posts.purge = function(pid, callback) {
Posts.exists(pid, function(err, exists) { Posts.exists(pid, function(err, exists) {
if (err || !exists) { if (err || !exists) {

@ -21,7 +21,7 @@ var async = require('async'),
}; };
function toggleDelete(tid, uid, isDelete, callback) { function toggleDelete(tid, uid, isDelete, callback) {
topics.getTopicFields(tid, ['tid', 'cid', 'deleted', 'title', 'mainPid'], function(err, topicData) { topics.getTopicFields(tid, ['tid', 'cid', 'uid', 'deleted', 'title', 'mainPid'], function(err, topicData) {
if (err) { if (err) {
return callback(err); return callback(err);
} }

Loading…
Cancel
Save