mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: use loash when possible (#7230)
This commit is contained in:
committed by
Barış Soner Uşaklı
parent
a4ab13d323
commit
e1ca2d81f9
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = function (db, module) {
|
||||
var helpers = module.helpers.postgres;
|
||||
@@ -44,9 +45,7 @@ SELECT $1::TEXT, m
|
||||
value = [value];
|
||||
}
|
||||
|
||||
keys = keys.filter(function (k, i, a) {
|
||||
return a.indexOf(k) === i;
|
||||
});
|
||||
keys = _.uniq(keys);
|
||||
|
||||
module.transaction(function (tx, done) {
|
||||
var query = tx.client.query.bind(tx.client);
|
||||
|
||||
@@ -167,19 +167,14 @@ function build(targets, options, callback) {
|
||||
return aliases[target];
|
||||
})
|
||||
// filter nonexistent targets
|
||||
.filter(Boolean)
|
||||
// map multitargets to their sets
|
||||
.reduce(function (prev, target) {
|
||||
if (Array.isArray(targetHandlers[target])) {
|
||||
return prev.concat(targetHandlers[target]);
|
||||
}
|
||||
.filter(Boolean);
|
||||
|
||||
return prev.concat(target);
|
||||
}, [])
|
||||
// unique
|
||||
.filter(function (target, i, arr) {
|
||||
return arr.indexOf(target) === i;
|
||||
});
|
||||
// map multitargets to their sets
|
||||
targets = _.uniq(_.flatMap(targets, target => (
|
||||
Array.isArray(targetHandlers[target]) ?
|
||||
targetHandlers[target] :
|
||||
target
|
||||
)));
|
||||
|
||||
winston.verbose('[build] building the following targets: ' + targets.join(', '));
|
||||
|
||||
|
||||
@@ -558,11 +558,9 @@ Notifications.merge = function (notifications, callback) {
|
||||
case 'notifications:user_posted_to':
|
||||
case 'notifications:user_flagged_post_in':
|
||||
case 'notifications:user_flagged_user':
|
||||
var usernames = set.map(function (notifObj) {
|
||||
var usernames = _.uniq(set.map(function (notifObj) {
|
||||
return notifObj && notifObj.user && notifObj.user.username;
|
||||
}).filter(function (username, idx, array) {
|
||||
return array.indexOf(username) === idx;
|
||||
});
|
||||
}));
|
||||
var numUsers = usernames.length;
|
||||
|
||||
var title = utils.decodeHTMLEntities(notifications[modifyIndex].topicTitle || '');
|
||||
|
||||
@@ -81,31 +81,6 @@ module.exports = function (Plugins) {
|
||||
}
|
||||
|
||||
Plugins.prepareForBuild = function (targets, callback) {
|
||||
if (targets.includes('client js bundle')) {
|
||||
Plugins.clientScripts.length = 0;
|
||||
}
|
||||
|
||||
if (targets.includes('admin js bundle')) {
|
||||
Plugins.acpScripts.length = 0;
|
||||
}
|
||||
|
||||
if (targets.includes('client side styles') || targets.includes('admin control panel styles')) {
|
||||
Plugins.cssFiles.length = 0;
|
||||
Plugins.lessFiles.length = 0;
|
||||
if (targets.includes('admin control panel styles')) {
|
||||
Plugins.acpLessFiles.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (targets.includes('sounds')) {
|
||||
Plugins.soundpacks.length = 0;
|
||||
}
|
||||
|
||||
if (targets.includes('languages')) {
|
||||
Plugins.languageData.languages = [];
|
||||
Plugins.languageData.namespaces = [];
|
||||
}
|
||||
|
||||
var map = {
|
||||
'plugin static dirs': ['staticDirs'],
|
||||
'requirejs modules': ['modules'],
|
||||
@@ -117,13 +92,27 @@ module.exports = function (Plugins) {
|
||||
languages: ['languageData'],
|
||||
};
|
||||
|
||||
var fields = targets.reduce(function (prev, target) {
|
||||
if (!map[target]) {
|
||||
return prev;
|
||||
var fields = _.uniq(_.flatMap(targets, target => map[target] || []));
|
||||
|
||||
// clear old data before build
|
||||
fields.forEach((field) => {
|
||||
switch (field) {
|
||||
case 'clientScripts':
|
||||
case 'acpScripts':
|
||||
case 'cssFiles':
|
||||
case 'lessFiles':
|
||||
case 'acpLessFiles':
|
||||
Plugins[field].length = 0;
|
||||
break;
|
||||
case 'soundpack':
|
||||
Plugins.soundpacks.length = 0;
|
||||
break;
|
||||
case 'languageData':
|
||||
Plugins.languageData.languages = [];
|
||||
Plugins.languageData.namespaces = [];
|
||||
break;
|
||||
// do nothing for modules and staticDirs
|
||||
}
|
||||
return prev.concat(map[target]);
|
||||
}, []).filter(function (field, i, arr) {
|
||||
return arr.indexOf(field) === i;
|
||||
});
|
||||
|
||||
winston.verbose('[plugins] loading the following fields from plugin data: ' + fields.join(', '));
|
||||
|
||||
Reference in New Issue
Block a user