don't sleep unnecessarily
This commit is contained in:
parent
ce5102caf7
commit
2c18a1a57c
|
@ -55,12 +55,15 @@ func (l *Location) cachedAddress() (Address, bool) {
|
|||
return val, ok
|
||||
}
|
||||
|
||||
func (l *Location) fetchAddress() Address {
|
||||
func (l *Location) fetchAddress(shallWait bool) (addr Address, nextShallWait bool) {
|
||||
if l == nil {
|
||||
return Address{}
|
||||
return addr, false
|
||||
}
|
||||
if cachedAddress, hasKey := l.cachedAddress(); hasKey {
|
||||
return cachedAddress
|
||||
return cachedAddress, false
|
||||
}
|
||||
if shallWait {
|
||||
time.Sleep(sleepBetweenLookup)
|
||||
}
|
||||
content, err := NominatimRequest(l)
|
||||
if err == nil && len(content) > 0 {
|
||||
|
@ -69,10 +72,10 @@ func (l *Location) fetchAddress() Address {
|
|||
if err == nil {
|
||||
address := d.Address.simpleAddress()
|
||||
knownAddresses[l.String()] = address
|
||||
return address
|
||||
return address, true
|
||||
}
|
||||
}
|
||||
return Address{Error: errors.New("fetchAddress: " + err.Error())}
|
||||
return Address{Error: errors.New("fetchAddress: " + err.Error())}, true
|
||||
}
|
||||
|
||||
func (l *Location) String() string {
|
||||
|
@ -84,11 +87,9 @@ func (l *Location) String() string {
|
|||
|
||||
func fetchAddresses(locations []Location) map[Location]Address {
|
||||
addresses := make(map[Location]Address)
|
||||
for i, location := range locations {
|
||||
addresses[location] = location.fetchAddress()
|
||||
if i < len(locations)-1 {
|
||||
time.Sleep(sleepBetweenLookup) // TODO: unnötig bei gecacheten
|
||||
}
|
||||
nextShallWait := false
|
||||
for _, location := range locations {
|
||||
addresses[location], nextShallWait = location.fetchAddress(nextShallWait)
|
||||
}
|
||||
return addresses
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user