better topic delete restore

v1.18.x
Baris Soner Usakli 11 years ago
parent 9b88dcdc14
commit 9d1a295b85

@ -67,7 +67,10 @@ var winston = require('winston'),
return callback(new Error('topic-already-deleted')); return callback(new Error('topic-already-deleted'));
} }
topics.delete(tid); topics.delete(tid, function(err) {
if(err) {
return callback(err);
}
db.decrObjectField('global', 'topicCount'); db.decrObjectField('global', 'topicCount');
@ -87,7 +90,8 @@ var winston = require('winston'),
tid: tid tid: tid
}); });
}); });
} });
};
ThreadTools.restore = function(tid, uid, callback) { ThreadTools.restore = function(tid, uid, callback) {
topics.getTopicField(tid, 'deleted', function(err, deleted) { topics.getTopicField(tid, 'deleted', function(err, deleted) {
@ -99,7 +103,10 @@ var winston = require('winston'),
return callback(new Error('topic-already-restored')); return callback(new Error('topic-already-restored'));
} }
topics.restore(tid); topics.restore(tid, function(err) {
if(err) {
return callback(err);
}
db.incrObjectField('global', 'topicCount'); db.incrObjectField('global', 'topicCount');
@ -121,7 +128,8 @@ var winston = require('winston'),
tid:tid tid:tid
}); });
}); });
} });
};
ThreadTools.lock = function(tid, uid, callback) { ThreadTools.lock = function(tid, uid, callback) {
topics.setTopicField(tid, 'locked', 1); topics.setTopicField(tid, 'locked', 1);

@ -1154,29 +1154,61 @@ var async = require('async'),
}); });
} }
Topics.delete = function(tid) { Topics.delete = function(tid, callback) {
Topics.setTopicField(tid, 'deleted', 1); async.parallel([
db.sortedSetRemove('topics:recent', tid); function(next) {
db.sortedSetRemove('topics:posts', tid); Topics.setTopicField(tid, 'deleted', 1, next);
db.sortedSetRemove('topics:views', tid); },
function(next) {
db.sortedSetRemove('topics:recent', tid, next);
},
function(next) {
db.sortedSetRemove('topics:posts', tid, next);
},
function(next) {
db.sortedSetRemove('topics:views', tid, next);
},
function(next) {
Topics.getTopicField(tid, 'cid', function(err, cid) { Topics.getTopicField(tid, 'cid', function(err, cid) {
db.incrObjectFieldBy('category:' + cid, 'topic_count', -1); if(err) {
return next(err);
}
db.incrObjectFieldBy('category:' + cid, 'topic_count', -1, next);
}); });
} }
], callback);
};
Topics.restore = function(tid) { Topics.restore = function(tid, callback) {
Topics.setTopicField(tid, 'deleted', 0);
Topics.getTopicFields(tid, ['lastposttime', 'postcount', 'viewcount'], function(err, topicData) { Topics.getTopicFields(tid, ['lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
db.sortedSetAdd('topics:recent', topicData.lastposttime, tid); if(err) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid); return callback(err);
db.sortedSetAdd('topics:views', topicData.viewcount, tid); }
});
async.parallel([
function(next) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
function(next) {
db.sortedSetAdd('topics:recent', topicData.lastposttime, tid, next);
},
function(next) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid, next);
},
function(next) {
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
},
function(next) {
Topics.getTopicField(tid, 'cid', function(err, cid) { Topics.getTopicField(tid, 'cid', function(err, cid) {
db.incrObjectFieldBy('category:' + cid, 'topic_count', 1); if(err) {
return next(err);
}
db.incrObjectFieldBy('category:' + cid, 'topic_count', 1, next);
}); });
} }
], callback);
});
};
Topics.reIndexTopic = function(tid, callback) { Topics.reIndexTopic = function(tid, callback) {
Topics.getPids(tid, function(err, pids) { Topics.getPids(tid, function(err, pids) {

Loading…
Cancel
Save