Skip to content

Node.js based forum software built for the modern web

deleting a user will delete topic tags too

barisusaklid8fd29581eb8
diff --git a/src/topics/tags.js b/src/topics/tags.js
index 92f4b089a6..7d36c8c678 100644
--- a/src/topics/tags.js
+++ b/src/topics/tags.js
@@ -57,34 +57,35 @@ module.exports = function(Topics) {
}
Topics.updateTags = function(tid, tags) {
- async.parallel({
- timestamp: function(next) {
- Topics.getTopicField(tid, 'timestamp', next);
- },
- currentTags: function(next) {
- Topics.getTopicTags(tid, next);
+ Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
+ if (!err) {
+ Topics.deleteTopicTags(tid, function(err) {
+ if (!err) {
+ Topics.createTags(tags, tid, timestamp);
+ }
+ });
}
- }, function(err, results) {
- removeTopicTags(tid, results.currentTags, function(err) {
- if (!err) {
- Topics.createTags(tags, tid, results.timestamp);
- }
- });
});
};
- function removeTopicTags(tid, tags, callback) {
- async.parallel([
- function(next) {
- db.delete('topic:' + tid + ':tags', next);
- },
- function(next) {
- async.each(tags, function(tag, next) {
- db.sortedSetRemove('tag:' + tag + ':topics', tid, next);
- }, next);
+ Topics.deleteTopicTags = function(tid, callback) {
+ Topics.getTopicTags(tid, function(err, tags) {
+ if (err) {
+ return callback(err);
}
- ], callback);
- }
+
+ async.parallel([
+ function(next) {
+ db.delete('topic:' + tid + ':tags', next);
+ },
+ function(next) {
+ async.each(tags, function(tag, next) {
+ db.sortedSetRemove('tag:' + tag + ':topics', tid, next);
+ }, next);
+ }
+ ], callback);
+ });
+ };
Topics.searchTags = function(query, callback) {
if (!query || query.length === 0) {
diff --git a/src/user/delete.js b/src/user/delete.js
index 33f0f8d10e..b03d13e42b 100644
--- a/src/user/delete.js
+++ b/src/user/delete.js
@@ -153,7 +153,6 @@ module.exports = function(User) {
}
function deleteTopic(tid, callback) {
-
async.parallel([
function(next) {
db.delete('tid:' + tid + ':followers', next);
@@ -175,6 +174,9 @@ module.exports = function(User) {
},
function(next) {
deleteTopicFromCategory(tid, next);
+ },
+ function(next) {
+ topics.deleteTopicTags(tid, next);
}
], function(err) {
if (err) {