mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 13:16:04 -06:00
Add map accessible cacheLocations
This commit is contained in:
13
api.go
13
api.go
@@ -98,6 +98,7 @@ type Location struct {
|
||||
|
||||
var (
|
||||
cachedLocations []Location
|
||||
cachedLocationsMap map[uint]Location
|
||||
cacheExpiry time.Time
|
||||
)
|
||||
|
||||
@@ -129,21 +130,25 @@ func GetLocations() []Location {
|
||||
return nil
|
||||
}
|
||||
|
||||
locations := make([]Location, 0, 150)
|
||||
cachedLocations := make([]Location, 0, 150)
|
||||
|
||||
doc.Find("input.property").Each(func(i int, s *goquery.Selection) {
|
||||
matches := parsePattern.FindStringSubmatch(s.Parent().Text())
|
||||
id, _ := strconv.ParseUint(matches[3], 10, 32)
|
||||
|
||||
locations = append(locations, Location{
|
||||
cachedLocations = append(cachedLocations, Location{
|
||||
id: uint(id),
|
||||
name: matches[1],
|
||||
address: matches[2],
|
||||
})
|
||||
})
|
||||
|
||||
cachedLocations = locations
|
||||
// Build the map
|
||||
cachedLocationsMap = make(map[uint]Location, len(cachedLocations))
|
||||
for _, location := range cachedLocations {
|
||||
cachedLocationsMap[location.id] = location
|
||||
}
|
||||
cacheExpiry = time.Now().Add(time.Hour * 3)
|
||||
|
||||
return locations
|
||||
return cachedLocations
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user