From 4ed9b1ac635710ef0df06094c09412adff34b42e Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sun, 9 Aug 2026 02:56:22 -0700 Subject: [PATCH 1/2] Rate-limit unloaded map tile retries --- main.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2622cc2..9a362dd 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,23 @@ import ( ms "pfeifer.dev/mapd/settings" ) +const mapLoadRetryDelay = time.Second + +type mapLoadRetryState struct { + lastAttempt time.Time +} + +func (s *mapLoadRetryState) shouldAttempt(loaded bool, box m.Box, position m.Position, now time.Time) bool { + if !box.PosInside(position) { + return true + } + return !loaded && now.Sub(s.lastAttempt) >= mapLoadRetryDelay +} + +func (s *mapLoadRetryState) recordAttempt(now time.Time) { + s.lastAttempt = now +} + func main() { ms.Settings.Default() // set defaults so settings not already in param are defaulted settingsLoaded := ms.Settings.Load() // try loading settings before cli @@ -24,6 +41,7 @@ func main() { state := State{} state.Init() + mapLoadRetry := mapLoadRetryState{} extendedState := ExtendedState{ Pub: cereal.NewPublisher("mapdExtendedOut", cereal.MapdExtendedOutCreator), @@ -92,15 +110,19 @@ func main() { if gpsSuccess { state.DistanceSinceLastPosition = 0 state.Position = m.PosFromLocation(location) - box := state.Data.Box() pos := m.PosFromLocation(location) - if len(state.Data.Ways()) == 0 || !box.PosInside(pos) { + mapLoadTime := time.Now() + if mapLoadRetry.shouldAttempt(state.Data.Loaded, state.Data.Box(), pos, mapLoadTime) { state.Data, err = maps.FindWaysAroundPosition(pos) + mapLoadRetry.recordAttempt(mapLoadTime) if err != nil { slog.Debug("", "error", errors.Wrap(err, "Could not find ways around location")) continue } } + if !state.Data.Loaded { + continue + } state.CurrentWay, err = GetCurrentWay(state.CurrentWay, state.NextWays, &state.Data, location) if err != nil { From 84cf7098a153dff3cf312258f9dd5a22d3b55b2e Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sun, 9 Aug 2026 08:44:44 -0700 Subject: [PATCH 2/2] Keep clearing route state when a tile fails to load --- main.go | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index 9a362dd..6f4395d 100644 --- a/main.go +++ b/main.go @@ -14,21 +14,6 @@ import ( const mapLoadRetryDelay = time.Second -type mapLoadRetryState struct { - lastAttempt time.Time -} - -func (s *mapLoadRetryState) shouldAttempt(loaded bool, box m.Box, position m.Position, now time.Time) bool { - if !box.PosInside(position) { - return true - } - return !loaded && now.Sub(s.lastAttempt) >= mapLoadRetryDelay -} - -func (s *mapLoadRetryState) recordAttempt(now time.Time) { - s.lastAttempt = now -} - func main() { ms.Settings.Default() // set defaults so settings not already in param are defaulted settingsLoaded := ms.Settings.Load() // try loading settings before cli @@ -41,7 +26,7 @@ func main() { state := State{} state.Init() - mapLoadRetry := mapLoadRetryState{} + var lastMapLoadAttempt time.Time extendedState := ExtendedState{ Pub: cereal.NewPublisher("mapdExtendedOut", cereal.MapdExtendedOutCreator), @@ -111,18 +96,16 @@ func main() { state.DistanceSinceLastPosition = 0 state.Position = m.PosFromLocation(location) pos := m.PosFromLocation(location) + box := state.Data.Box() mapLoadTime := time.Now() - if mapLoadRetry.shouldAttempt(state.Data.Loaded, state.Data.Box(), pos, mapLoadTime) { + if !box.PosInside(pos) || (!state.Data.Loaded && mapLoadTime.Sub(lastMapLoadAttempt) >= mapLoadRetryDelay) { state.Data, err = maps.FindWaysAroundPosition(pos) - mapLoadRetry.recordAttempt(mapLoadTime) + lastMapLoadAttempt = mapLoadTime if err != nil { slog.Debug("", "error", errors.Wrap(err, "Could not find ways around location")) continue } } - if !state.Data.Loaded { - continue - } state.CurrentWay, err = GetCurrentWay(state.CurrentWay, state.NextWays, &state.Data, location) if err != nil {