mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-05 07:47:26 +02:00
closes #2379
also fixed a bug where tags with 0 topics were showing up in /tags
This commit is contained in:
@@ -49,7 +49,7 @@ tagsController.getTag = function(req, res, next) {
|
||||
};
|
||||
|
||||
tagsController.getTags = function(req, res, next) {
|
||||
topics.getTags(0, 99, function(err, tags) {
|
||||
topics.getTags(0, 100, function(err, tags) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -11,5 +11,9 @@ Tags.update = function(socket, data, callback) {
|
||||
topics.updateTag(data.tag, data, callback);
|
||||
};
|
||||
|
||||
Tags.deleteTags = function(socket, data, callback) {
|
||||
topics.deleteTags(data.tags, callback);
|
||||
};
|
||||
|
||||
|
||||
module.exports = Tags;
|
||||
@@ -64,7 +64,7 @@ module.exports = function(Topics) {
|
||||
function updateTagCount(tag, callback) {
|
||||
callback = callback || function() {};
|
||||
Topics.getTagTopicCount(tag, function(err, count) {
|
||||
if (!err) {
|
||||
if (!err && count) {
|
||||
db.sortedSetAdd('tags:topic:count', count, tag, callback);
|
||||
}
|
||||
});
|
||||
@@ -78,13 +78,49 @@ module.exports = function(Topics) {
|
||||
db.sortedSetCard('tag:' + tag + ':topics', callback);
|
||||
};
|
||||
|
||||
Topics.deleteTags = function(tags, callback) {
|
||||
if (!Array.isArray(tags) || !tags.length) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
removeTagsFromTopics(tags, next);
|
||||
},
|
||||
function(next) {
|
||||
var keys = tags.map(function(tag) {
|
||||
return 'tag:' + tag + ':topics';
|
||||
});
|
||||
db.deleteAll(keys, next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetRemove('tags:topic:count', tags, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
function removeTagsFromTopics(tags, callback) {
|
||||
async.eachLimit(tags, 50, function(tag, next) {
|
||||
db.getSortedSetRange('tag:' + tag + ':topics', 0, -1, function(err, tids) {
|
||||
if (err || !tids.length) {
|
||||
return next(err);
|
||||
}
|
||||
var keys = tids.map(function(tid) {
|
||||
return 'topic:' + tid + ':tags';
|
||||
});
|
||||
|
||||
db.setsRemove(keys, tag, next);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
||||
Topics.deleteTag = function(tag) {
|
||||
db.delete('tag:' + tag + ':topics');
|
||||
db.sortedSetRemove('tags:topic:count', tag);
|
||||
};
|
||||
|
||||
Topics.getTags = function(start, end, callback) {
|
||||
db.getSortedSetRevRangeWithScores('tags:topic:count', start, end, function(err, tags) {
|
||||
Topics.getTags = function(start, count, callback) {
|
||||
db.getSortedSetRevRangeByScoreWithScores('tags:topic:count', start, count, '+inf', 1, function(err, tags) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<div class="panel-body">
|
||||
<p>Select tags via clicking and/or dragging, use shift to select multiple.</p>
|
||||
<button class="btn btn-primary btn-md" id="modify">Modify Selected Tags</button>
|
||||
<button class="btn btn-warning btn-md" id="deleteSelected">Delete Selected Tags</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -50,5 +51,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user