mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
fix: updateCategoryTagsCount
This commit is contained in:
@@ -42,12 +42,13 @@ module.exports = function (Topics) {
|
|||||||
const counts = await db.sortedSetsCard(
|
const counts = await db.sortedSetsCard(
|
||||||
tags.map(tag => `cid:${cid}:tag:${tag}:topics`)
|
tags.map(tag => `cid:${cid}:tag:${tag}:topics`)
|
||||||
);
|
);
|
||||||
|
const tagToCount = _.zipObject(tags, counts);
|
||||||
const set = `cid:${cid}:tags`;
|
const set = `cid:${cid}:tags`;
|
||||||
|
|
||||||
const bulkAdd = tags.filter((tag, index) => counts[index] > 0)
|
const bulkAdd = tags.filter(tag => tagToCount[tag] > 0)
|
||||||
.map((tag, index) => [set, counts[index], tag]);
|
.map(tag => [set, tagToCount[tag], tag]);
|
||||||
|
|
||||||
const bulkRemove = tags.filter((tag, index) => counts[index] <= 0)
|
const bulkRemove = tags.filter(tag => tagToCount[tag] <= 0)
|
||||||
.map(tag => [set, tag]);
|
.map(tag => [set, tag]);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@@ -289,13 +290,15 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTopicTags = async function (tid) {
|
Topics.getTopicTags = async function (tid) {
|
||||||
return await db.getSetMembers(`topic:${tid}:tags`);
|
const tags = await db.getSetMembers(`topic:${tid}:tags`);
|
||||||
|
return tags.sort();
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTopicsTags = async function (tids) {
|
Topics.getTopicsTags = async function (tids) {
|
||||||
return await db.getSetsMembers(
|
const keys = tids.map(tid => `topic:${tid}:tags`);
|
||||||
tids.map(tid => `topic:${tid}:tags`)
|
const tags = await db.getSetsMembers(keys);
|
||||||
);
|
tags.forEach(tags => tags.sort());
|
||||||
|
return tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTopicTagsObjects = async function (tid) {
|
Topics.getTopicTagsObjects = async function (tid) {
|
||||||
@@ -314,6 +317,7 @@ module.exports = function (Topics) {
|
|||||||
topicTags.forEach((tags, index) => {
|
topicTags.forEach((tags, index) => {
|
||||||
if (Array.isArray(tags)) {
|
if (Array.isArray(tags)) {
|
||||||
topicTags[index] = tags.map(tag => tagDataMap[tag]);
|
topicTags[index] = tags.map(tag => tagDataMap[tag]);
|
||||||
|
topicTags[index].sort((tag1, tag2) => tag2.value - tag1.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user