diff --git a/src/database/mongo.js b/src/database/mongo.js index 9976d323ab..455ef87190 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -108,6 +108,12 @@ } }); + db.collection('search').ensureIndex({key: 1, id: 1}, {background: true}, function(err) { + if(err) { + winston.error('Error creating index ' + err.message); + } + }); + if(typeof callback === 'function') { callback(); } diff --git a/src/database/mongo/main.js b/src/database/mongo/main.js index 3c24830ffa..dacce8d9f6 100644 --- a/src/database/mongo/main.js +++ b/src/database/mongo/main.js @@ -13,7 +13,7 @@ module.exports = function(db, module) { content: content }; - db.collection('search').update({id:id, key:key}, {$set:data}, {upsert:true, w: 1}, function(err) { + db.collection('search').update({key:key, id:id}, {$set:data}, {upsert:true, w: 1}, function(err) { if(err) { winston.error('Error indexing ' + err.message); } @@ -41,7 +41,7 @@ module.exports = function(db, module) { module.searchRemove = function(key, id, callback) { callback = callback || helpers.noop; - db.collection('search').remove({id:id, key:key}, callback); + db.collection('search').remove({key:key, id:id}, callback); }; module.flushdb = function(callback) { diff --git a/src/favourites.js b/src/favourites.js index cb4de2e97e..741d3a3c4f 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -131,7 +131,14 @@ var async = require('async'), return callback(new Error('[[error:not-enough-reputation-to-downvote]]')); } - toggleVote('downvote', pid, uid, callback); + toggleVote('downvote', pid, uid, function(err, votes) { + if (err) return callback(err); + plugins.fireHook('action:post.downvote', { + pid: pid, + uid: uid + }); + callback(null, votes); + }); }); };