From 32899bd0f9349e15426984660d3118fc721af095 Mon Sep 17 00:00:00 2001 From: karitham Date: Thu, 22 Jan 2026 20:12:12 +0100 Subject: [PATCH] remove dead code --- sync/adapter.go | 47 ---------------------------------------------- sync/batch_test.go | 5 ++--- sync/publish.go | 2 +- sync/sync_test.go | 29 ---------------------------- 4 files changed, 3 insertions(+), 80 deletions(-) diff --git a/sync/adapter.go b/sync/adapter.go index 693c687..9dae009 100644 --- a/sync/adapter.go +++ b/sync/adapter.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "log/slog" - "math/rand" "net" "strings" "time" @@ -178,19 +177,6 @@ func prepareRecords(batch []PlayRecord) []PlayRecord { return atprotoRecords } -func waitForRetry(ctx context.Context, delay time.Duration) bool { - timer := time.NewTimer(delay) - defer timer.Stop() - - select { - case <-timer.C: - return true - case <-ctx.Done(): - slog.Debug("retry cancelled due to context done") - return false - } -} - func defaultProgressLog(f func(ProgressReport)) func(ProgressReport) { if f != nil { return f @@ -253,31 +239,6 @@ func logResult(success, errors int, startTime time.Time) { slog.String("rate", formatRate(ratePerMinute(success, time.Since(startTime))))) } -func backoff(attempt int) time.Duration { - if attempt <= 0 { - return BaseRetryDelay - } - - // Calculate exponential delay: BaseRetryDelay * 2^(attempt-1) - // We use uint(attempt-1) because 1<<0 is 1 (for first retry) - exp := min(attempt-1, 31) - - delay := BaseRetryDelay * time.Duration(1< MaxRetryDelay || delay <= 0 { - delay = MaxRetryDelay - } - - // Add up to 25% jitter - var jitter time.Duration - if delay > 4 { - jitter = time.Duration(rand.Int63n(int64(delay / 4))) - } - - return delay + jitter -} - func PublishBatch(ctx context.Context, client ATProtoClient, did string, batch []PlayRecord, storage cache.Storage) error { if len(batch) == 0 { return nil @@ -332,14 +293,6 @@ func IsTransientError(err error) bool { return isTransientError(err) } -func Backoff(attempt int) time.Duration { - return backoff(attempt) -} - -func WaitForRetry(ctx context.Context, delay time.Duration) bool { - return waitForRetry(ctx, delay) -} - func isTransientError(err error) bool { if err == nil { return false diff --git a/sync/batch_test.go b/sync/batch_test.go index 1be2b58..09c9d73 100644 --- a/sync/batch_test.go +++ b/sync/batch_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "maps" "net/http" "strings" "sync" @@ -44,9 +45,7 @@ func newMockStorage() *mockStorage { func (m *mockStorage) SaveRecords(did string, records map[string][]byte) error { m.mu.Lock() defer m.mu.Unlock() - for k, v := range records { - m.unpublished[k] = v - } + maps.Copy(m.unpublished, records) return nil } diff --git a/sync/publish.go b/sync/publish.go index 7fc0e57..21c5897 100644 --- a/sync/publish.go +++ b/sync/publish.go @@ -102,7 +102,7 @@ func Publish(ctx context.Context, client AuthClient, opts PublishOptions) Publis }). Build() - err := failsafe.With[any](retryPolicy).WithContext(ctx).Run(func() error { + err := failsafe.With(retryPolicy).WithContext(ctx).Run(func() error { return PublishBatch(ctx, atprotoClient, did, batch, opts.Storage) }) if err != nil { diff --git a/sync/sync_test.go b/sync/sync_test.go index 6d746b6..72e5cf7 100644 --- a/sync/sync_test.go +++ b/sync/sync_test.go @@ -1,7 +1,6 @@ package sync import ( - "fmt" "testing" "time" ) @@ -298,31 +297,3 @@ func TestFindDuplicates(t *testing.T) { }) } } - -func TestBackoff(t *testing.T) { - tests := []struct { - attempt int - min time.Duration - max time.Duration - }{ - {0, BaseRetryDelay, BaseRetryDelay + (BaseRetryDelay / 4)}, - {1, BaseRetryDelay, BaseRetryDelay + (BaseRetryDelay / 4)}, - {2, BaseRetryDelay * 2, BaseRetryDelay*2 + (BaseRetryDelay * 2 / 4)}, - {3, BaseRetryDelay * 4, BaseRetryDelay*4 + (BaseRetryDelay * 4 / 4)}, - {10, MaxRetryDelay, MaxRetryDelay + (MaxRetryDelay / 4)}, - {100, MaxRetryDelay, MaxRetryDelay + (MaxRetryDelay / 4)}, - } - - for _, tt := range tests { - t.Run(fmt.Sprintf("attempt %d", tt.attempt), func(t *testing.T) { - d := backoff(tt.attempt) - if d < tt.min { - t.Errorf("backoff(%d) = %v, want >= %v", tt.attempt, d, tt.min) - } - // Allow for jitter in the max check - if d > tt.max { - t.Errorf("backoff(%d) = %v, want <= %v", tt.attempt, d, tt.max) - } - }) - } -} -- 2.51.2