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

@ -1154,29 +1154,61 @@ var async = require('async'),
});
}
Topics.delete = function(tid) {
Topics.setTopicField(tid, 'deleted', 1);
db.sortedSetRemove('topics:recent', tid);
db.sortedSetRemove('topics:posts', tid);
db.sortedSetRemove('topics:views', tid);
Topics.delete = function(tid, callback) {
async.parallel([
function(next) {
Topics.setTopicField(tid, 'deleted', 1, next);
},
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) {
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.setTopicField(tid, 'deleted', 0);
Topics.restore = function(tid, callback) {
Topics.getTopicFields(tid, ['lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
db.sortedSetAdd('topics:recent', topicData.lastposttime, tid);
db.sortedSetAdd('topics:posts', topicData.postcount, tid);
db.sortedSetAdd('topics:views', topicData.viewcount, tid);
});
if(err) {
return callback(err);
}
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) {
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.getPids(tid, function(err, pids) {

Loading…
Cancel
Save