Use a Map instead of Object to preserve failure ordering

pull/21833/head
Luke Barnard 2018-06-15 15:49:33 +01:00
parent f08274585e
commit f22f2d7bd6
1 changed files with 7 additions and 6 deletions

View File

@ -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];
}