Skip to content

Commit 4dfbc71

Browse files
committed
parallelize hashAttributes to match Rokt wSDK
1 parent 8c91a8b commit 4dfbc71

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/roktManager.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,30 @@ export default class RoktManager {
267267
return {};
268268
}
269269

270-
const hashedAttributes: IRoktPartnerAttributes = {};
270+
// Get own property keys only
271+
const keys = Object.keys(attributes);
272+
273+
if (keys.length === 0) {
274+
return {};
275+
}
271276

272-
for (const key in attributes) {
277+
// Hash all attributes in parallel
278+
const hashPromises = keys.map(async (key) => {
273279
const attributeValue = attributes[key];
274-
275-
hashedAttributes[key] = attributeValue;
276-
277280
const hashedValue = await this.hashSha256(attributeValue);
278-
281+
return { key, attributeValue, hashedValue };
282+
});
283+
284+
const results = await Promise.all(hashPromises);
285+
286+
// Build the result object
287+
const hashedAttributes: IRoktPartnerAttributes = {};
288+
for (const { key, attributeValue, hashedValue } of results) {
289+
hashedAttributes[key] = attributeValue;
279290
if (hashedValue) {
280291
hashedAttributes[`${key}sha256`] = hashedValue;
281292
}
282293
}
283-
284294
return hashedAttributes;
285295

286296
} catch (error) {

0 commit comments

Comments
 (0)