Bladeren bron

refactor(reader): clarify a ScheduleNextCheck call

Right after `originalFeed.CheckedNow()`, `originalFeed.ScheduleNextCheck` is
called, with its second argument being `refreshdelay`, a time.Duration set to its implicit
default value. The variable `refreshdelay` is never reassigned, until much
deeper in the function. This commit replaces it with `time.Duration(0)`, to
make it explicit that no special delay is expected, and declares it later in a
restricted scope.
jvoisin 1 maand geleden
bovenliggende
commit
54df471d0e
1 gewijzigde bestanden met toevoegingen van 2 en 4 verwijderingen
  1. 2 4
      internal/reader/handler/handler.go

+ 2 - 4
internal/reader/handler/handler.go

@@ -211,7 +211,6 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
 	}
 
 	weeklyEntryCount := 0
-	var refreshDelay time.Duration
 	if config.Opts.PollingScheduler() == model.SchedulerEntryFrequency {
 		var weeklyCountErr error
 		weeklyEntryCount, weeklyCountErr = store.WeeklyFeedEntryCount(userID, feedID)
@@ -221,7 +220,7 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
 	}
 
 	originalFeed.CheckedNow()
-	originalFeed.ScheduleNextCheck(weeklyEntryCount, refreshDelay)
+	originalFeed.ScheduleNextCheck(weeklyEntryCount, time.Duration(0))
 
 	requestBuilder := fetcher.NewRequestBuilder()
 	requestBuilder.WithUsernameAndPassword(originalFeed.Username, originalFeed.Password)
@@ -251,7 +250,6 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
 		slog.Warn("Feed is rate limited",
 			slog.String("feed_url", originalFeed.FeedURL),
 			slog.Int("retry_delay_in_seconds", int(retryDelay.Seconds())),
-			slog.Int("refresh_delay_in_minutes", int(refreshDelay.Minutes())),
 			slog.Int("calculated_next_check_interval_in_minutes", int(calculatedNextCheckInterval.Minutes())),
 			slog.Time("new_next_check_at", originalFeed.NextCheckAt),
 		)
@@ -320,7 +318,7 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
 		feedTTLValue := updatedFeed.TTL
 		cacheControlMaxAgeValue := responseHandler.CacheControlMaxAge()
 		expiresValue := responseHandler.Expires()
-		refreshDelay = max(feedTTLValue, cacheControlMaxAgeValue, expiresValue)
+		refreshDelay := max(feedTTLValue, cacheControlMaxAgeValue, expiresValue)
 
 		// Set the next check at with updated arguments.
 		calculatedNextCheckInterval := originalFeed.ScheduleNextCheck(weeklyEntryCount, refreshDelay)