wait for all callbacks when creating tags

v1.18.x
barisusakli 9 years ago
parent 051c5077eb
commit 5454862c1c

@ -18,29 +18,31 @@ module.exports = function(Topics) {
return callback(); return callback();
} }
plugins.fireHook('filter:tags.filter', {tags: tags, tid: tid}, function(err, data) { async.waterfall([
if (err) { function (next) {
return callback(err); plugins.fireHook('filter:tags.filter', {tags: tags, tid: tid}, next);
} },
function (data, next) {
tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5); tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5);
async.each(tags, function(tag, next) {
tag = Topics.cleanUpTag(tag);
if (tag.length < (meta.config.minimumTagLength || 3)) {
return next();
}
db.setAdd('topic:' + tid + ':tags', tag);
db.sortedSetAdd('tag:' + tag + ':topics', timestamp, tid, function(err) { async.each(tags, function(tag, next) {
if (!err) { tag = Topics.cleanUpTag(tag);
updateTagCount(tag); if (tag.length < (meta.config.minimumTagLength || 3)) {
return next();
} }
next(err);
}); async.parallel([
}, callback); async.apply(db.setAdd, 'topic:' + tid + ':tags', tag),
}); async.apply(db.sortedSetAdd, 'tag:' + tag + ':topics', timestamp, tid)
], function(err) {
if (err) {
return next(err);
}
updateTagCount(tag, next);
});
}, next);
}
], callback);
}; };
Topics.cleanUpTag = function(tag) { Topics.cleanUpTag = function(tag) {

Loading…
Cancel
Save