Remove failures when marking them for tracking

This commit is contained in:
Luke Barnard 2018-06-15 14:45:11 +01:00
parent 62601d657d
commit 4a8442901d

View file

@ -98,9 +98,17 @@ export default class DecryptionFailureTracker {
* @param {number} nowTs the timestamp that represents the time now. * @param {number} nowTs the timestamp that represents the time now.
*/ */
checkFailures(nowTs) { checkFailures(nowTs) {
const failuresGivenGrace = this.failures.filter( const failuresGivenGrace = [];
(f) => nowTs > f.ts + DecryptionFailureTracker.GRACE_PERIOD_MS, const failuresNotReady = [];
); while (this.failures.length > 0) {
const f = this.failures.shift();
if (nowTs > f.ts + DecryptionFailureTracker.GRACE_PERIOD_MS) {
failuresGivenGrace.push(f);
} else {
failuresNotReady.push(f);
}
}
this.failures = failuresNotReady;
// Only track one failure per event // Only track one failure per event
const dedupedFailuresMap = failuresGivenGrace.reduce( const dedupedFailuresMap = failuresGivenGrace.reduce(