feat: use arrow functions

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 208c821eaf
commit 3100d803c7

@ -25,25 +25,18 @@ module.exports = function (Topics) {
plugins.fireHook('filter:tags.filter', { tags: tags, tid: tid }, next); plugins.fireHook('filter:tags.filter', { tags: tags, tid: tid }, next);
}, },
function (data, next) { function (data, next) {
tags = _.uniq(data.tags); tags = _.uniq(data.tags).slice(0, meta.config.maximumTagsPerTopic || 5)
tags = tags.slice(0, meta.config.maximumTagsPerTopic || 5); .map(tag => utils.cleanUpTag(tag, meta.config.maximumTagLength))
tags = tags.map(function (tag) { .filter(tag => tag && tag.length >= (meta.config.minimumTagLength || 3));
return utils.cleanUpTag(tag, meta.config.maximumTagLength);
}).filter(function (tag) {
return tag && tag.length >= (meta.config.minimumTagLength || 3);
});
filterCategoryTags(tags, tid, next); filterCategoryTags(tags, tid, next);
}, },
function (_tags, next) { function (_tags, next) {
tags = _tags; tags = _tags;
var keys = tags.map(function (tag) {
return 'tag:' + tag + ':topics';
});
async.parallel([ async.parallel([
async.apply(db.setAdd, 'topic:' + tid + ':tags', tags), async.apply(db.setAdd, 'topic:' + tid + ':tags', tags),
async.apply(db.sortedSetsAdd, keys, timestamp, tid), async.apply(db.sortedSetsAdd, tags.map(tag => 'tag:' + tag + ':topics'), timestamp, tid),
], function (err) { ], function (err) {
next(err); next(err);
}); });
@ -129,9 +122,7 @@ module.exports = function (Topics) {
db.sortedSetAdd('tag:' + newTagName + ':topics', scores, tids, next); db.sortedSetAdd('tag:' + newTagName + ':topics', scores, tids, next);
}, },
function (next) { function (next) {
var keys = tids.map(function (tid) { const keys = tids.map(tid => 'topic:' + tid + ':tags');
return 'topic:' + tid + ':tags';
});
async.series([ async.series([
async.apply(db.sortedSetRemove, 'tag:' + tag + ':topics', tids), async.apply(db.sortedSetRemove, 'tag:' + tag + ':topics', tids),
@ -158,9 +149,7 @@ module.exports = function (Topics) {
Topics.getTagTopicCount(tag, next); Topics.getTagTopicCount(tag, next);
}, },
function (count, next) { function (count, next) {
count = count || 0; db.sortedSetAdd('tags:topic:count', count || 0, tag, next);
db.sortedSetAdd('tags:topic:count', count, tag, next);
}, },
], callback); ], callback);
} }
@ -183,22 +172,16 @@ module.exports = function (Topics) {
removeTagsFromTopics(tags, next); removeTagsFromTopics(tags, next);
}, },
function (next) { function (next) {
var keys = tags.map(function (tag) { const keys = tags.map(tag => 'tag:' + tag + ':topics');
return 'tag:' + tag + ':topics';
});
db.deleteAll(keys, next); db.deleteAll(keys, next);
}, },
function (next) { function (next) {
db.sortedSetRemove('tags:topic:count', tags, next); db.sortedSetRemove('tags:topic:count', tags, next);
}, },
function (next) { function (next) {
db.deleteAll(tags.map(function (tag) { db.deleteAll(tags.map(tag => 'tag:' + tag), next);
return 'tag:' + tag;
}), next);
}, },
], function (err) { ], err => callback(err));
callback(err);
});
}; };
function removeTagsFromTopics(tags, callback) { function removeTagsFromTopics(tags, callback) {
@ -207,10 +190,7 @@ module.exports = function (Topics) {
if (err || !tids.length) { if (err || !tids.length) {
return next(err); return next(err);
} }
var keys = tids.map(function (tid) { const keys = tids.map(tid => 'topic:' + tid + ':tags');
return 'topic:' + tid + ':tags';
});
db.setsRemove(keys, tag, next); db.setsRemove(keys, tag, next);
}); });
}, callback); }, callback);
@ -267,12 +247,11 @@ module.exports = function (Topics) {
}; };
Topics.getTopicsTagsObjects = function (tids, callback) { Topics.getTopicsTagsObjects = function (tids, callback) {
const sets = tids.map(tid => 'topic:' + tid + ':tags');
var uniqueTopicTags; var uniqueTopicTags;
var topicTags; var topicTags;
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSetsMembers(sets, next); Topics.getTopicsTags(tids, next);
}, },
function (_topicTags, next) { function (_topicTags, next) {
topicTags = _topicTags; topicTags = _topicTags;
@ -298,10 +277,8 @@ module.exports = function (Topics) {
topicTags.forEach(function (tags, index) { topicTags.forEach(function (tags, index) {
if (Array.isArray(tags)) { if (Array.isArray(tags)) {
topicTags[index] = tags.map(function (tag) { return tagData[tag]; }); topicTags[index] = tags.map(tag => tagData[tag]);
topicTags[index].sort(function (tag1, tag2) { topicTags[index].sort((tag1, tag2) => tag2.score - tag1.score);
return tag2.score - tag1.score;
});
} }
}); });
@ -336,10 +313,7 @@ module.exports = function (Topics) {
db.delete('topic:' + tid + ':tags', next); db.delete('topic:' + tid + ':tags', next);
}, },
function (next) { function (next) {
var sets = tags.map(function (tag) { const sets = tags.map(tag => 'tag:' + tag + ':topics');
return 'tag:' + tag + ':topics';
});
db.sortedSetsRemove(sets, tid, next); db.sortedSetsRemove(sets, tid, next);
}, },
function (next) { function (next) {
@ -349,9 +323,7 @@ module.exports = function (Topics) {
}, },
], next); ], next);
}, },
], function (err) { ], err => callback(err));
callback(err);
});
}; };
Topics.searchTags = function (data, callback) { Topics.searchTags = function (data, callback) {
@ -450,10 +422,7 @@ module.exports = function (Topics) {
db.sortedSetScores('tags:topic:count', tags, next); db.sortedSetScores('tags:topic:count', tags, next);
}, },
tagData: function (next) { tagData: function (next) {
tags = tags.map(function (tag) { tags = tags.map(tag => ({ value: tag }));
return { value: tag };
});
Topics.getTagData(tags, next); Topics.getTagData(tags, next);
}, },
}, next); }, next);
@ -462,9 +431,7 @@ module.exports = function (Topics) {
results.tagData.forEach(function (tag, index) { results.tagData.forEach(function (tag, index) {
tag.score = results.counts[index]; tag.score = results.counts[index];
}); });
results.tagData.sort(function (a, b) { results.tagData.sort((a, b) => b.score - a.score);
return b.score - a.score;
});
searchResult.tags = results.tagData; searchResult.tags = results.tagData;
searchResult.matchCount = results.tagData.length; searchResult.matchCount = results.tagData.length;
searchResult.pageCount = 1; searchResult.pageCount = 1;
@ -496,9 +463,7 @@ module.exports = function (Topics) {
Topics.getTopics(tids, uid, next); Topics.getTopics(tids, uid, next);
}, },
function (topics, next) { function (topics, next) {
topics = topics.filter(function (topic) { topics = topics.filter(t => t && !t.deleted && parseInt(t.uid, 10) !== parseInt(uid, 10));
return topic && !topic.deleted && parseInt(topic.uid, 10) !== parseInt(uid, 10);
});
next(null, topics); next(null, topics);
}, },
], callback); ], callback);

Loading…
Cancel
Save