From f22f2d7bd68b88d8b9ca200b0cdc2cff8481151a Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 15 Jun 2018 15:49:33 +0100 Subject: [PATCH] Use a Map instead of Object to preserve failure ordering --- src/DecryptionFailureTracker.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/DecryptionFailureTracker.js b/src/DecryptionFailureTracker.js index 2f3d286d55..e668884f64 100644 --- a/src/DecryptionFailureTracker.js +++ b/src/DecryptionFailureTracker.js @@ -129,17 +129,18 @@ export default class DecryptionFailureTracker { // Only track one failure per event const dedupedFailuresMap = failuresGivenGrace.reduce( - (result, failure) => { + (map, failure) => { if (!this.trackedEventHashMap[eventIdHash(failure.failedEventId)]) { - return {...result, [failure.failedEventId]: failure}; + return map.set(failure.failedEventId, failure); } else { - return result; + return map; } }, - {}, + // Use a map to preseve key ordering + new Map(), ); - const trackedEventIds = Object.keys(dedupedFailuresMap); + const trackedEventIds = [...dedupedFailuresMap.keys()]; this.trackedEventHashMap = trackedEventIds.reduce( (result, eventId) => ({...result, [eventIdHash(eventId)]: true}), @@ -148,7 +149,7 @@ export default class DecryptionFailureTracker { this.saveTrackedEventHashMap(); - const dedupedFailures = trackedEventIds.map((k) => dedupedFailuresMap[k]); + const dedupedFailures = dedupedFailuresMap.values(); this.failuresToTrack = [...this.failuresToTrack, ...dedupedFailures]; }