Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use per-method packages instead of a single import for lodash #411

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions src/server/flow/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
const find = require('lodash.find');

/*
This class will be allowed only for BullMQ
Expand Down Expand Up @@ -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,
});
Expand Down
7 changes: 4 additions & 3 deletions src/server/queue/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const _ = require('lodash');
const find = require('lodash.find');
const assignIn = require('lodash.assignin');

class Queues {
constructor(config) {
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -95,7 +96,7 @@ class Queues {

let queue;
if (isBee) {
_.extend(options, {
assignIn(options, {
isWorker: false,
getEvents: false,
sendEvents: false,
Expand Down
7 changes: 4 additions & 3 deletions src/server/views/api/bulkAction.js
Original file line number Diff line number Diff line change
@@ -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`,
Expand All @@ -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))
);
Expand Down
4 changes: 2 additions & 2 deletions src/server/views/dashboard/jobDetails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
const omit = require('lodash.omit');
const JobHelpers = require('../helpers/jobHelpers');

async function handler(req, res) {
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 13 additions & 8 deletions src/server/views/dashboard/queueJobsByState.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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' ||
Expand All @@ -160,7 +165,7 @@ async function _html(req, res) {
hasFlows: Flows.hasFlows(),
pages,
pageSize,
lastPage: _.last(pages),
lastPage: last(pages),
order,
});
}
Expand Down
15 changes: 10 additions & 5 deletions src/server/views/helpers/handlebars.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -140,7 +145,7 @@ const helpers = {
};

module.exports = function registerHelpers(hbs, {queues}) {
_.each(helpers, (fn, helper) => {
forEach(helpers, (fn, helper) => {
hbs.registerHelper(helper, fn);
});

Expand Down
6 changes: 4 additions & 2 deletions src/server/views/helpers/queueHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const _ = require('lodash');
const pickBy = require("lodash.pickby");
const includes = require('lodash.includes');

/**
* Formats the number into "human readable" number/
Expand Down Expand Up @@ -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(
Expand Down