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:
17
api.go
17
api.go
@@ -97,8 +97,9 @@ type Location struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cachedLocations []Location
|
cachedLocations []Location
|
||||||
cacheExpiry time.Time
|
cachedLocationsMap map[uint]Location
|
||||||
|
cacheExpiry time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -129,21 +130,25 @@ func GetLocations() []Location {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
locations := make([]Location, 0, 150)
|
cachedLocations := make([]Location, 0, 150)
|
||||||
|
|
||||||
doc.Find("input.property").Each(func(i int, s *goquery.Selection) {
|
doc.Find("input.property").Each(func(i int, s *goquery.Selection) {
|
||||||
matches := parsePattern.FindStringSubmatch(s.Parent().Text())
|
matches := parsePattern.FindStringSubmatch(s.Parent().Text())
|
||||||
id, _ := strconv.ParseUint(matches[3], 10, 32)
|
id, _ := strconv.ParseUint(matches[3], 10, 32)
|
||||||
|
|
||||||
locations = append(locations, Location{
|
cachedLocations = append(cachedLocations, Location{
|
||||||
id: uint(id),
|
id: uint(id),
|
||||||
name: matches[1],
|
name: matches[1],
|
||||||
address: matches[2],
|
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)
|
cacheExpiry = time.Now().Add(time.Hour * 3)
|
||||||
|
|
||||||
return locations
|
return cachedLocations
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user