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) {
topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) {
if (err) {
return callback(err);
}
if (!topicData || !topicData.cid) {
return callback();
}
var cid = topicData.cid;
Categories.onNewPostMade = function(cid, pinned, postData, callback) {
if (!cid || !postData) {
return callback();
}
async.parallel([
function(next) {
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);
},
function(next) {
db.incrObjectField('category:' + cid, 'post_count', next);
},
function(next) {
if (parseInt(topicData.pinned, 10) === 1) {
next();
} else {
db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next);
}
},
function(next) {
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, next);
async.parallel([
function(next) {
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);
},
function(next) {
db.incrObjectField('category:' + cid, 'post_count', next);
},
function(next) {
if (parseInt(pinned, 10) === 1) {
next();
} else {
db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, 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
};
for(var field in data) {
if (data.hasOwnProperty(field)) {
setData[field] = data[field];
if (data.hasOwnProperty(field) && data[field]) {
setData[field] = data[field].toString();
}
}

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

@ -68,7 +68,13 @@ module.exports = function(Posts) {
topics.onNewPostMade(postData, 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) {
db.sortedSetAdd('posts:pid', timestamp, postData.pid, next);

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

@ -21,7 +21,7 @@ var async = require('async'),
};
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) {
return callback(err);
}

Loading…
Cancel
Save