diff --git a/src/controllers/tags.js b/src/controllers/tags.js index 70626e8f27..9c03cba0af 100644 --- a/src/controllers/tags.js +++ b/src/controllers/tags.js @@ -18,6 +18,9 @@ tagsController.getTag = function(req, res, next) { return next(err); } data.tag = tag; + if (data.topics && !data.topics.length) { + topics.deleteTag(tag); + } res.render('tag', data); }); }); diff --git a/src/topics/tags.js b/src/topics/tags.js index 275eb2dd94..a1d64dd4be 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -27,6 +27,11 @@ module.exports = function(Topics) { db.sortedSetCard('tag:' + tag + ':topics', callback); }; + Topics.deleteTag = function(tag) { + db.delete('tag:' + tag + ':topics'); + db.setRemove('tags', tag); + }; + Topics.getTags = function(callback) { db.getSetMembers('tags', callback); };