v1.18.x
Julian Lam
parent fdd2dc322b
commit 42d33f8338

@ -75,10 +75,6 @@ var winston = require('winston'),
events.logPostEdit(uid, pid); events.logPostEdit(uid, pid);
db.searchRemove('post', pid, function() {
db.searchIndex('post', content, pid);
});
async.parallel([ async.parallel([
function(next) { function(next) {
posts.getPostField(pid, 'tid', function(err, tid) { posts.getPostField(pid, 'tid', function(err, tid) {
@ -89,12 +85,12 @@ var winston = require('winston'),
topics.setTopicField(tid, 'title', title); topics.setTopicField(tid, 'title', title);
topics.setTopicField(tid, 'slug', slug); topics.setTopicField(tid, 'slug', slug);
db.searchRemove('topic', tid, function() {
db.searchIndex('topic', title, tid);
});
} }
posts.getPostData(pid, function(err, postData) {
plugins.fireHook('action:post.edit', postData);
});
next(null, { next(null, {
tid: tid, tid: tid,
isMainPost: isMainPost isMainPost: isMainPost
@ -129,7 +125,8 @@ var winston = require('winston'),
var success = function() { var success = function() {
posts.setPostField(pid, 'deleted', 1); posts.setPostField(pid, 'deleted', 1);
db.decrObjectField('global', 'postCount'); db.decrObjectField('global', 'postCount');
db.searchRemove('post', pid);
plugins.fireHook('action:post.delete', pid);
events.logPostDelete(uid, pid); events.logPostDelete(uid, pid);
@ -205,7 +202,7 @@ var winston = require('winston'),
}); });
db.searchIndex('post', postData.content, pid); plugins.fireHook('action:post.restore', postData);
// Restore topic if it is the only post // Restore topic if it is the only post
topics.getTopicField(postData.tid, 'postcount', function(err, count) { topics.getTopicField(postData.tid, 'postcount', function(err, count) {

@ -87,8 +87,6 @@ var db = require('./database'),
plugins.fireHook('action:post.save', postData); plugins.fireHook('action:post.save', postData);
db.searchIndex('post', content, postData.pid);
next(null, postData); next(null, postData);
}); });
} }
@ -447,28 +445,6 @@ var db = require('./database'),
} }
} }
Posts.reIndexPids = function(pids, callback) {
function reIndex(pid, next) {
Posts.getPostField(pid, 'content', function(err, content) {
if(err) {
return next(err);
}
db.searchRemove('post', pid, function() {
if (content && content.length) {
db.searchIndex('post', content, pid);
}
next();
});
});
}
async.each(pids, reIndex, callback);
}
// this function should really be called User.getFavouritePosts // this function should really be called User.getFavouritePosts
Posts.getFavourites = function(uid, start, end, callback) { Posts.getFavourites = function(uid, start, end, callback) {
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) { db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) {

@ -402,7 +402,10 @@ var path = require('path'),
var limit = 50; var limit = 50;
function searchPosts(callback) { function searchPosts(callback) {
db.search('post', req.params.term, limit, function(err, pids) { Plugins.fireHook('filter:search.query', {
index: 'post',
query: req.params.terms
}, function(err, pids) {
if (err) { if (err) {
return callback(err, null); return callback(err, null);
} }
@ -412,7 +415,10 @@ var path = require('path'),
} }
function searchTopics(callback) { function searchTopics(callback) {
db.search('topic', req.params.term, limit, function(err, tids) { Plugins.fireHook('filter:search.query', {
index: 'topic',
query: req.params.terms
}, function(err, tids) {
if (err) { if (err) {
return callback(err, null); return callback(err, null);
} }

@ -24,7 +24,6 @@ var DebugRoute = function(app) {
}); });
}); });
app.get('/cid/:cid', function (req, res) { app.get('/cid/:cid', function (req, res) {
categories.getCategoryData(req.params.cid, function (err, data) { categories.getCategoryData(req.params.cid, function (err, data) {
if (data) { if (data) {
@ -55,24 +54,6 @@ var DebugRoute = function(app) {
}); });
}); });
app.get('/groups/prune', function(req, res) {
var Groups = require('../groups');
Groups.prune(function(err) {
res.send('pruned');
});
});
app.get('/reindex', function (req, res) {
topics.reIndexAll(function (err) {
if (err) {
return res.json(err);
} else {
res.send('Topics and users reindexed');
}
});
});
app.get('/test', function(req, res) { app.get('/test', function(req, res) {
// categories.getModerators(1, function(err, mods) { // categories.getModerators(1, function(err, mods) {
// res.json(mods); // res.json(mods);

@ -11,7 +11,8 @@ var winston = require('winston'),
posts = require('./posts'), posts = require('./posts'),
meta = require('./meta'), meta = require('./meta'),
websockets = require('./socket.io'), websockets = require('./socket.io'),
events = require('./events'); events = require('./events'),
Plugins = require('./plugins');
(function(ThreadTools) { (function(ThreadTools) {
@ -76,7 +77,7 @@ var winston = require('winston'),
ThreadTools.lock(tid); ThreadTools.lock(tid);
db.searchRemove('topic', tid); Plugins.fireHook('action:topic.delete', tid);
events.logTopicDelete(uid, tid); events.logTopicDelete(uid, tid);
@ -120,9 +121,7 @@ var winston = require('winston'),
tid: tid tid: tid
}); });
topics.getTopicField(tid, 'title', function(err, title) { Plugins.fireHook('action:topic.restore', tid);
db.searchIndex('topic', title, tid);
});
callback(null, { callback(null, {
tid:tid tid:tid

@ -16,7 +16,8 @@ var async = require('async'),
postTools = require('./postTools'), postTools = require('./postTools'),
notifications = require('./notifications'), notifications = require('./notifications'),
favourites = require('./favourites'), favourites = require('./favourites'),
meta = require('./meta'); meta = require('./meta'),
Plugins = require('./plugins');
(function(Topics) { (function(Topics) {
@ -48,7 +49,7 @@ var async = require('async'),
} }
db.sortedSetAdd('topics:tid', timestamp, tid); db.sortedSetAdd('topics:tid', timestamp, tid);
db.searchIndex('topic', title, tid); Plugins.fireHook('action:topic.save', tid);
user.addTopicIdToUser(uid, tid, timestamp); user.addTopicIdToUser(uid, tid, timestamp);
@ -1209,25 +1210,4 @@ var async = require('async'),
], callback); ], callback);
}); });
}; };
Topics.reIndexTopic = function(tid, callback) {
Topics.getPids(tid, function(err, pids) {
if (err) {
return callback(err);
}
posts.reIndexPids(pids, callback);
});
}
Topics.reIndexAll = function(callback) {
db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {
if (err) {
return callback(err);
}
async.each(tids, Topics.reIndexTopic, callback);
});
}
}(exports)); }(exports));

Loading…
Cancel
Save