diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-07 22:07:27 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-07 22:07:27 +0200 |
| commit | ebc50a6600fcf4ebc53df4846f790bb05757b3df (patch) | |
| tree | 64e66a0cbed140a75aa580fe9ba02d510b68601c /internal/state | |
| parent | 545e65fe16c761822f0999b8f4ab05f1cd325975 (diff) | |
feat(sync): add throttled sync modev0.12.0
Introduce an opt-in throttle that skips inactive repos based on local
activity and per-repo cooldowns, and bump the version to 0.12.0.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'internal/state')
| -rw-r--r-- | internal/state/state.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/state/state.go b/internal/state/state.go index c2a62ed..3288db1 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -11,6 +11,9 @@ import ( // State represents the persistent state of gitsyncer type State struct { LastBatchRun time.Time `json:"lastBatchRun"` + // Per-repo sync tracking for throttling + LastRepoSync map[string]time.Time `json:"lastRepoSync,omitempty"` + NextRepoSyncAllowed map[string]time.Time `json:"nextRepoSyncAllowed,omitempty"` } // Manager handles state persistence @@ -77,3 +80,48 @@ func (s *State) HasRunWithinWeek() bool { func (s *State) UpdateBatchRunTime() { s.LastBatchRun = time.Now() } + +// EnsureRepoMaps initializes per-repo maps if needed +func (s *State) EnsureRepoMaps() { + if s.LastRepoSync == nil { + s.LastRepoSync = make(map[string]time.Time) + } + if s.NextRepoSyncAllowed == nil { + s.NextRepoSyncAllowed = make(map[string]time.Time) + } +} + +// GetLastRepoSync returns the last sync time for a repo +func (s *State) GetLastRepoSync(repoName string) time.Time { + if s == nil || s.LastRepoSync == nil { + return time.Time{} + } + return s.LastRepoSync[repoName] +} + +// GetNextRepoSyncAllowed returns the next allowed sync time for a repo +func (s *State) GetNextRepoSyncAllowed(repoName string) time.Time { + if s == nil || s.NextRepoSyncAllowed == nil { + return time.Time{} + } + return s.NextRepoSyncAllowed[repoName] +} + +// SetRepoSync updates the last sync time and next allowed sync time for a repo +func (s *State) SetRepoSync(repoName string, lastSync time.Time, nextAllowed time.Time) { + if s == nil { + return + } + s.EnsureRepoMaps() + s.LastRepoSync[repoName] = lastSync + s.NextRepoSyncAllowed[repoName] = nextAllowed +} + +// SetNextRepoSyncAllowed updates only the next allowed sync time for a repo +func (s *State) SetNextRepoSyncAllowed(repoName string, nextAllowed time.Time) { + if s == nil { + return + } + s.EnsureRepoMaps() + s.NextRepoSyncAllowed[repoName] = nextAllowed +} |
