Skip to content

Commit

Permalink
fix(telemetry): send events on trailing edge of the frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Dec 11, 2024
1 parent 1c82456 commit c43f83f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/background/telemetry/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,16 @@ export default class Metrics {
_timeToExpired(type, frequency) {
if (frequency === 'all') return 0;

const last = this.storage[`${type}_${frequency}`] || 0;
const key = `${type}_${frequency}`;

// 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.saveStorage(this.storage);
}

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

return last ? last - frequency_ago : 0;
Expand Down

0 comments on commit c43f83f

Please sign in to comment.