add delta sync before each reconcile, have it not repeat if it's been done in the last minute

This commit is contained in:
Miloš Jovanović 2026-09-24 20:01:01 -07:00
parent ccb6b3277d
commit f98a23418f
3 changed files with 22 additions and 0 deletions

17
sync.go
View file

@ -44,3 +44,20 @@ func (s *Server) SyncRoster(ctx context.Context) error {
log.Printf("synced %d users (since=%d)", len(users), since)
return s.store.SetLastSync(started)
}
// syncIfStale runs a delta sync unless one completed within maxAge (1 min)
// Serialized so a burst of runs triggers one sync, not one each.
func (s *Server) syncIfStale(ctx context.Context, maxAge time.Duration) error {
s.syncMu.Lock()
defer s.syncMu.Unlock()
last, err := s.store.LastSync()
if err != nil {
return err
}
if time.Since(time.Unix(last, 0)) < maxAge {
return nil
}
return s.SyncRoster(ctx)
}