Skip to content

Commit 5430b18

Browse files
committed
fix: memory
1 parent 513dd1f commit 5430b18

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

backend/pkd/gasstation/gsbaserepo.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func createPostCodeMaps() (map[int]pcmodel.PostCodeLocation, map[int]pcmodel.Sta
8282
return postCodePostCodeLocationMap, idStateDataMap, idCountyDataMap
8383
}
8484

85-
func createGasStationIdGasPriceMap(postCodeGasStationsMap *map[string][]gsmodel.GasStation, timeframe TimeFrame) map[string][]gsmodel.GasPrice {
86-
gasPrices := findGasPricesByTimeframe(postCodeGasStationsMap, timeframe)
85+
func createGasStationIdGasPriceMap(gasStations *[]gsmodel.GasStation, timeframe TimeFrame) map[string][]gsmodel.GasPrice {
86+
gasPrices := findGasPricesByTimeframe(gasStations, timeframe)
8787
//log.Printf("gasPrices: %v", len(gasPrices))
8888
gasStationIdGasPriceMap := make(map[string][]gsmodel.GasPrice)
8989
for _, myGasPrice := range gasPrices {
@@ -98,8 +98,8 @@ func createGasStationIdGasPriceMap(postCodeGasStationsMap *map[string][]gsmodel.
9898
return gasStationIdGasPriceMap
9999
}
100100

101-
func createGasStationIdGasPriceArrayMap(postCodeGasStationsMap *map[string][]gsmodel.GasStation, timeframe TimeFrame) map[string][]gsmodel.GasPrice {
102-
gasPrices := findGasPricesByTimeframe(postCodeGasStationsMap, timeframe)
101+
func createGasStationIdGasPriceArrayMap(gasStations *[]gsmodel.GasStation, timeframe TimeFrame) map[string][]gsmodel.GasPrice {
102+
gasPrices := findGasPricesByTimeframe(gasStations, timeframe)
103103
//log.Printf("gasPrices: %v", len(gasPrices))
104104
gasStationIdGasPriceMap := make(map[string][]gsmodel.GasPrice)
105105
for _, myGasPrice := range gasPrices {
@@ -113,12 +113,10 @@ func createGasStationIdGasPriceArrayMap(postCodeGasStationsMap *map[string][]gsm
113113
return gasStationIdGasPriceMap
114114
}
115115

116-
func findGasPricesByTimeframe(postCodeGasStationsMap *map[string][]gsmodel.GasStation, timeframe TimeFrame) []gsmodel.GasPrice {
116+
func findGasPricesByTimeframe(gasStations *[]gsmodel.GasStation, timeframe TimeFrame) []gsmodel.GasPrice {
117117
var gasStationIds []string
118-
for _, myGasStations := range *postCodeGasStationsMap {
119-
for _, myGasStation := range myGasStations {
120-
gasStationIds = append(gasStationIds, myGasStation.ID)
121-
}
118+
for _, myGasStation := range *gasStations {
119+
gasStationIds = append(gasStationIds, myGasStation.ID)
122120
}
123121
//log.Printf("gasStationIds: %v", len(gasStationIds))
124122
gasPrices := FindPricesByStids(&gasStationIds, 0, timeframe, false)

backend/pkd/gasstation/gsrepo.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,15 @@ func ReCalcCountyStatePrices() {
162162
log.Printf("recalcCountyStatePrices started.")
163163
myStart := time.Now()
164164
postCodePostCodeLocationMap, idStateDataMap, idCountyDataMap, postCodeGasStationsMap := createPostCodeGasStationMaps()
165-
gasStationIdGasPriceMap := createGasStationIdGasPriceMap(&postCodeGasStationsMap, Month)
166-
log.Printf("gasStationIdGasPriceMap: %v", len(gasStationIdGasPriceMap))
165+
//gasStationIdGasPriceMap := createGasStationIdGasPriceMap(&postCodeGasStationsMap, Month)
167166
resetDataMaps(&idStateDataMap, &idCountyDataMap)
168167
//sum up prices and count stations
169168
for _, myPostCodeLocation := range postCodePostCodeLocationMap {
170169
myPostCode := postcode.FormatPostCode(myPostCodeLocation.PostCode)
171-
for _, myGasStation := range postCodeGasStationsMap[myPostCode] {
172-
for _, myGasPrice := range gasStationIdGasPriceMap[myGasStation.ID] {
170+
gasStations := postCodeGasStationsMap[myPostCode]
171+
//log.Printf("gasStationIdGasPriceMap: %v", len(gasStations))
172+
for _, myGasStationPrices := range createGasStationIdGasPriceMap(&gasStations, Month) {
173+
for _, myGasPrice := range myGasStationPrices {
173174
if myGasPrice.E5 < 10 && myGasPrice.E10 < 10 && myGasPrice.Diesel < 10 {
174175
continue
175176
}
@@ -234,10 +235,12 @@ func ReCalcCountyStatePrices() {
234235
}
235236

236237
func createCodeTimeSliceBuckets(postCodePostCodeLocationMap map[int]pcmodel.PostCodeLocation, postCodeGasStationsMap map[string][]gsmodel.GasStation) map[string]map[time.Time][]gsmodel.GasPrice {
237-
gasStationIdGasPriceMap := createGasStationIdGasPriceArrayMap(&postCodeGasStationsMap, Day)
238+
//gasStationIdGasPriceMap := createGasStationIdGasPriceArrayMap(&postCodeGasStationsMap, Day)
238239
postCodeTimeSliceBuckets := make(map[string]map[time.Time][]gsmodel.GasPrice)
239240
for _, myPostCodeLocation := range postCodePostCodeLocationMap {
240241
myPostCode := postcode.FormatPostCode(myPostCodeLocation.PostCode)
242+
gasStations := postCodeGasStationsMap[myPostCode]
243+
gasStationIdGasPriceMap := createGasStationIdGasPriceArrayMap(&gasStations, Day)
241244
for _, myGasStation := range postCodeGasStationsMap[myPostCode] {
242245
yesterday := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -1).Round(time.Hour)
243246
//yesterday := time.Now().AddDate(0, 0, -1).Round(time.Hour)
@@ -350,6 +353,7 @@ func CalcCountyTimeSlots() {
350353
log.Printf("calcCountyTimeSlots started.")
351354
myStart := time.Now()
352355
postCodePostCodeLocationMap, _, idCountyDataMap, postCodeGasStationsMap := createPostCodeGasStationMaps()
356+
353357
postCodeTimeSliceBuckets := createCodeTimeSliceBuckets(postCodePostCodeLocationMap, postCodeGasStationsMap)
354358
//log.Printf("postCodeTimeSliceBuckets: %v\n", len(postCodeGasStationsMap))
355359
database.DB.Transaction(func(tx *gorm.DB) error {

0 commit comments

Comments
 (0)