diff --git a/package.json b/package.json index 192339b8..439a0733 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,21 @@ "express": "^4.15.2", "express-handlebars": "^5.1.0", "handlebars": "^4.7.7", - "lodash": "^4.17.15", + "lodash.isempty": "^4.4.0", + "lodash.pickby": "^4.6.0", + "lodash.omit": "^4.5.0", + "lodash.isobject": "^3.0.2", + "lodash.transform": "^4.6.0", + "lodash.isstring": "^4.0.1", + "lodash.foreach": "^4.5.0", + "lodash.find": "^4.6.0", + "lodash.assignin": "^4.2.0", + "lodash.includes": "^4.3.0", + "lodash.pick": "^4.4.0", + "lodash.range": "^3.2.0", + "lodash.last": "^3.0.0", + "lodash.capitalize": "^4.2.1", + "lodash.ceil": "^4.0.4", "moment": "^2.29.1", "tablesort": "^5.0.1" }, diff --git a/src/server/flow/index.js b/src/server/flow/index.js index f56e3124..7435baca 100644 --- a/src/server/flow/index.js +++ b/src/server/flow/index.js @@ -1,4 +1,4 @@ -const _ = require('lodash'); +const find = require('lodash.find'); /* This class will be allowed only for BullMQ @@ -51,7 +51,7 @@ class Flows { } async get(connectionName, queueHost) { - const flowConfig = _.find(this._config.flows, { + const flowConfig = find(this._config.flows, { name: connectionName, hostId: queueHost, }); diff --git a/src/server/queue/index.js b/src/server/queue/index.js index 15b8f86c..20f271aa 100644 --- a/src/server/queue/index.js +++ b/src/server/queue/index.js @@ -1,4 +1,5 @@ -const _ = require('lodash'); +const find = require('lodash.find'); +const assignIn = require('lodash.assignin'); class Queues { constructor(config) { @@ -56,7 +57,7 @@ class Queues { } async get(queueName, queueHost) { - const queueConfig = _.find(this._config.queues, { + const queueConfig = find(this._config.queues, { name: queueName, hostId: queueHost, }); @@ -95,7 +96,7 @@ class Queues { let queue; if (isBee) { - _.extend(options, { + assignIn(options, { isWorker: false, getEvents: false, sendEvents: false, diff --git a/src/server/views/api/bulkAction.js b/src/server/views/api/bulkAction.js index ae8ae206..67eac12a 100644 --- a/src/server/views/api/bulkAction.js +++ b/src/server/views/api/bulkAction.js @@ -1,10 +1,11 @@ -const _ = require('lodash'); +const includes = require('lodash.includes'); +const isEmpty = require('lodash.isempty'); const ACTIONS = ['remove', 'retry', 'promote']; function bulkAction(action) { return async function handler(req, res) { - if (!_.includes(ACTIONS, action)) { + if (!includes(ACTIONS, action)) { res.status(401).send({ error: 'unauthorized action', details: `action ${action} not permitted`, @@ -19,7 +20,7 @@ function bulkAction(action) { const {jobs, queueState} = req.body; try { - if (!_.isEmpty(jobs)) { + if (!isEmpty(jobs)) { const jobsPromises = jobs.map((id) => queue.getJob(decodeURIComponent(id)) ); diff --git a/src/server/views/dashboard/jobDetails.js b/src/server/views/dashboard/jobDetails.js index 1e8c42a4..6dde0be0 100644 --- a/src/server/views/dashboard/jobDetails.js +++ b/src/server/views/dashboard/jobDetails.js @@ -1,4 +1,4 @@ -const _ = require('lodash'); +const omit = require('lodash.omit'); const JobHelpers = require('../helpers/jobHelpers'); async function handler(req, res) { @@ -28,7 +28,7 @@ async function handler(req, res) { if (json === 'true') { // Omit these private and non-stringifyable properties to avoid circular // references parsing errors. - return res.json(_.omit(job, 'domain', 'queue', '_events', '_eventsCount')); + return res.json(omit(job, 'domain', 'queue', '_events', '_eventsCount')); } const jobState = queue.IS_BEE ? job.status : await job.getState(); diff --git a/src/server/views/dashboard/queueJobsByState.js b/src/server/views/dashboard/queueJobsByState.js index 62b054cb..611f9168 100644 --- a/src/server/views/dashboard/queueJobsByState.js +++ b/src/server/views/dashboard/queueJobsByState.js @@ -1,4 +1,9 @@ -const _ = require('lodash'); +const includes = require('lodash.includes'); +const pick = require('lodash.pick'); +const range = require('lodash.range'); +const capitalize = require('lodash.capitalize'); +const last = require('lodash.last'); +const ceil = require('lodash.ceil'); const { BEE_STATES, BULL_STATES, @@ -25,7 +30,7 @@ function getStates(queue) { */ function isValidState(state, queue) { const validStates = getStates(queue); - return _.includes(validStates, state); + return includes(validStates, state); } async function handler(req, res) { @@ -53,11 +58,11 @@ async function _json(req, res) { if (queue.IS_BEE) { jobs = await queue.getJobs(state, {size: 1000}); jobs = jobs.map((j) => - _.pick(j, 'id', 'progress', 'data', 'options', 'status') + pick(j, 'id', 'progress', 'data', 'options', 'status') ); } else { const words = state.split('-'); - const finalStateName = words.map((word) => _.capitalize(word)).join(''); + const finalStateName = words.map((word) => capitalize(word)).join(''); jobs = await queue[`get${finalStateName}`](0, 1000); jobs = jobs.map((j) => j.toJSON()); } @@ -133,11 +138,11 @@ async function _html(req, res) { job.parent = JobHelpers.getKeyProperties(job.parentKey); } - let pages = _.range(page - 6, page + 7).filter((page) => page >= 1); + let pages = range(page - 6, page + 7).filter((page) => page >= 1); while (pages.length < 12) { - pages.push(_.last(pages) + 1); + pages.push(last(pages) + 1); } - pages = pages.filter((page) => page <= _.ceil(jobCounts[state] / pageSize)); + pages = pages.filter((page) => page <= ceil(jobCounts[state] / pageSize)); const disablePromote = !(state === 'delayed' && !queue.IS_BEE); const disableRetry = !( state === 'failed' || @@ -160,7 +165,7 @@ async function _html(req, res) { hasFlows: Flows.hasFlows(), pages, pageSize, - lastPage: _.last(pages), + lastPage: last(pages), order, }); } diff --git a/src/server/views/helpers/handlebars.js b/src/server/views/helpers/handlebars.js index 1b3ae82c..35566b01 100644 --- a/src/server/views/helpers/handlebars.js +++ b/src/server/views/helpers/handlebars.js @@ -1,14 +1,19 @@ const crypto = require('crypto'); const _ = require('lodash'); +const isObject = require('lodash.isobject'); +const transform = require('lodash.transform'); +const isString = require('lodash.isstring'); +const ceil = require('lodash.ceil'); +const forEach = require('lodash.foreach'); const Handlebars = require('handlebars'); const moment = require('moment'); const replacer = (key, value) => { - if (_.isObject(value)) { - return _.transform(value, (result, v, k) => { + if (isObject(value)) { + return transform(value, (result, v, k) => { result[Handlebars.Utils.escapeExpression(k)] = v; }); - } else if (_.isString(value)) { + } else if (isString(value)) { return Handlebars.Utils.escapeExpression(value); } else { return value; @@ -45,7 +50,7 @@ const helpers = { adjustedPage(currentPage, pageSize, newPageSize) { const firstId = (currentPage - 1) * pageSize; - return _.ceil(firstId / newPageSize) + 1; + return ceil(firstId / newPageSize) + 1; }, block(name) { @@ -140,7 +145,7 @@ const helpers = { }; module.exports = function registerHelpers(hbs, {queues}) { - _.each(helpers, (fn, helper) => { + forEach(helpers, (fn, helper) => { hbs.registerHelper(helper, fn); }); diff --git a/src/server/views/helpers/queueHelpers.js b/src/server/views/helpers/queueHelpers.js index 2e0f2e00..330907b3 100644 --- a/src/server/views/helpers/queueHelpers.js +++ b/src/server/views/helpers/queueHelpers.js @@ -1,4 +1,6 @@ const _ = require('lodash'); +const pickBy = require("lodash.pickby"); +const includes = require('lodash.includes'); /** * Formats the number into "human readable" number/ @@ -36,8 +38,8 @@ const Helpers = { const client = await queue.client; await client.info(); // update queue.client.serverInfo - const stats = _.pickBy(client.serverInfo, (value, key) => - _.includes(this._usefulMetrics, key) + const stats = pickBy(client.serverInfo, (value, key) => + includes(this._usefulMetrics, key) ); stats.used_memory = formatBytes(parseInt(stats.used_memory, 10)); stats.total_system_memory = formatBytes(