diff --git a/internal/stats/stats.go b/internal/stats/stats.go index 1d514a2..25ccd9f 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -7,17 +7,30 @@ import ( "time" "github.com/axllent/mailpit/config" + "github.com/axllent/mailpit/internal/logger" "github.com/axllent/mailpit/internal/storage" "github.com/axllent/mailpit/internal/updater" ) +// Stores cached version along with its expiry time and error count. +// Used to minimize repeated version lookups and track consecutive errors. +type versionCache struct { + // github version string + value string + // time to expire the cache + expiry time.Time + // count of consecutive errors + errCount int +} + var ( - // to prevent hammering Github for latest version - latestVersionCache string + // Version cache storing the latest GitHub version + vCache versionCache // StartedAt is set to the current ime when Mailpit starts startedAt time.Time + // sync mutex to prevent race condition with simultaneous requests mu sync.RWMutex smtpAccepted uint64 @@ -62,6 +75,12 @@ type AppInformation struct { } } +// Calculates exponential backoff duration based on the error count. +func getBackoff(errCount int) time.Duration { + backoff := min(time.Duration(1<