Skip to content

Commit

Permalink
Extract Date.now()
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Dec 11, 2024
1 parent c43f83f commit cd78163
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/background/telemetry/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,17 @@ export default class Metrics {
if (frequency === 'all') return 0;

const key = `${type}_${frequency}`;
const now = Date.now();

// Protect against calling events immediately after install for all frequencies
// They should trigger on the trailing edge of the frequency
if (!this.storage[key]) {
this.storage[key] = Date.now();
this.storage[key] = now;
this.saveStorage(this.storage);
}

const last = this.storage[key];
const frequency_ago = Date.now() - FREQUENCIES[frequency];
const frequency_ago = now - FREQUENCIES[frequency];

return last ? last - frequency_ago : 0;
}
Expand Down

0 comments on commit cd78163

Please sign in to comment.