delete tag if it has no topics left

This commit is contained in:
barisusakli
2014-05-21 20:25:35 -04:00
parent 56f442f283
commit 87fe5bf1bb
2 changed files with 8 additions and 0 deletions

View File

@@ -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);
});
});

View File

@@ -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);
};