Skip to content

Commit 5c674af

Browse files
authored
perf(metascraper): reduce getData allocations (microlinkhq#827)
1 parent 0333253 commit 5c674af

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/metascraper/src/get-data.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const debug = require('debug-logfmt')('metascraper:get-data')
44
const { findRule, has } = require('@metascraper/helpers')
55

66
const getData = async ({ rules, ...props }) => {
7-
const data = await Promise.all(
7+
const data = {}
8+
9+
await Promise.all(
810
rules.map(async ([propName, innerRules]) => {
911
const duration = debug.duration()
1012
let normalizedValue = null
@@ -26,11 +28,11 @@ const getData = async ({ rules, ...props }) => {
2628
duration(
2729
`${propName}=${normalizedValue} rules=${innerRules.length} status=${status}`
2830
)
29-
return [propName, normalizedValue]
31+
data[propName] = normalizedValue
3032
})
3133
)
3234

33-
return Object.fromEntries(data)
35+
return data
3436
}
3537

3638
module.exports = getData

0 commit comments

Comments
 (0)