Skip to content

Commit

Permalink
refactor: apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Feb 13, 2024
1 parent e9fb2f8 commit e6a52b4
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
AUTH_STATUS_INACTIVE,
} = require('../../adapters/networkhandler/authConstants');
const { FEATURE_FILTER_CODE, FEATURE_GZIP_SUPPORT } = require('./constant');
const { CommonUtils } = require('../../util/common');

// ========================================================================
// INLINERS
Expand Down Expand Up @@ -2143,17 +2144,10 @@ const parseConfigArray = (arr, key) => {
* @returns
*/
const findExistingBatch = (batch, metadataMap) => {
let existingBatch = null;

// eslint-disable-next-line no-restricted-syntax
for (const metadataItem of batch.metadata) {
if (metadataMap.has(metadataItem.jobId)) {
existingBatch = metadataMap.get(metadataItem.jobId);
break;
}
}

return existingBatch;
const existingMetadataItem = batch.metadata.find((metadataItem) =>
metadataMap.has(metadataItem.jobId),
);
return existingMetadataItem ? metadataMap.get(existingMetadataItem.jobId) : null;
};

/**
Expand Down Expand Up @@ -2192,10 +2186,8 @@ const combineBatchRequestsWithSameJobIds = (inputBatches) => {
if (existingBatch) {
// Merge batchedRequests arrays
existingBatch.batchedRequest = [
...(Array.isArray(existingBatch.batchedRequest)
? existingBatch.batchedRequest
: [existingBatch.batchedRequest]),
...(Array.isArray(batch.batchedRequest) ? batch.batchedRequest : [batch.batchedRequest]),
...CommonUtils.toArray(existingBatch.batchedRequest),
...CommonUtils.toArray(batch.batchedRequest),
];

// Merge metadata
Expand Down

0 comments on commit e6a52b4

Please sign in to comment.