Fix geocode map race between job feed and worker writes

This commit is contained in:
Ian Gulliver
2026-08-15 23:27:35 -07:00
parent fd52c948db
commit 8ddf729a92
+9 -7
View File
@@ -63,6 +63,12 @@ func (c *Cache) geocodeFamilies(model *Model) {
key string key string
address string address string
} }
pending := []job{}
for key, family := range model.Families {
if family.Address != "" {
pending = append(pending, job{key: key, address: family.Address})
}
}
jobs := make(chan job) jobs := make(chan job)
var wg sync.WaitGroup var wg sync.WaitGroup
var mu sync.Mutex var mu sync.Mutex
@@ -87,14 +93,10 @@ func (c *Cache) geocodeFamilies(model *Model) {
} }
}() }()
} }
total := 0 for _, j := range pending {
for key, family := range model.Families { jobs <- j
if family.Address != "" {
total++
jobs <- job{key: key, address: family.Address}
}
} }
close(jobs) close(jobs)
wg.Wait() wg.Wait()
log.Printf("geocoded %d of %d family addresses in %s", located, total, time.Since(start).Round(time.Millisecond)) log.Printf("geocoded %d of %d family addresses in %s", located, len(pending), time.Since(start).Round(time.Millisecond))
} }