Skip to content

Commit

Permalink
Remove unnecessary map to reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
levinmr committed Jan 2, 2025
1 parent 711ce58 commit ba4eff0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/actions/format_processed_analytics_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FormatProcessedAnalyticsData extends Action {
*/
async executeStrategy(context) {
context.logger.debug("Formatting analytics data");
const formattedAnalyticsData = {};
let formattedAnalyticsData = {};
for (const format of context.appConfig.formats) {
formattedAnalyticsData[format] = await ResultFormatter.formatResult(
context.processedAnalyticsData,
Expand All @@ -29,6 +29,7 @@ class FormatProcessedAnalyticsData extends Action {
}
context.processedAnalyticsData = undefined;
context.formattedAnalyticsData = formattedAnalyticsData;
formattedAnalyticsData = undefined;
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/process_results/result_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ const _formatJSON = (result, { slim }) => {
};

const _formatCSV = (result) => {
const mappedData = _mapCSVHeaders(result.data);
return csv.writeToString(mappedData, { headers: true });
return csv.writeToString(_mapCSVHeaders(result.data), { headers: true });
};

function _mapCSVHeaders(dataArray) {
return dataArray.map((dataItem) => {
return dataArray.forEach((dataItem, index) => {
const newDataItem = {};
Object.keys(dataItem).forEach((key) => {
if (_keyMappings[key]) {
Expand All @@ -48,7 +47,7 @@ function _mapCSVHeaders(dataArray) {
}
});

return newDataItem;
dataArray[index] = newDataItem;
});
}

Expand Down

0 comments on commit ba4eff0

Please sign in to comment.