Skip to content

Commit 1c3d865

Browse files
committed
fix: mem use
1 parent 50f2141 commit 1c3d865

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

backend/pkd/gasstation/gsbaserepo.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,33 @@ func findPricesByStids(stids *[]string, resultLimit int, timeframe TimeFrame) []
156156
}
157157
myQuery.Find(&values)
158158
//log.Printf("%v", values)
159-
myGasPrices = append(myGasPrices, values...)
159+
var lastUpdates = returnLastUpdatesGasStation(&values)
160+
//log.Printf("%v", lastUpdates)
161+
myGasPrices = append(myGasPrices, lastUpdates...)
160162
}
161163
return nil
162164
})
163165
return myGasPrices
164166
}
165167

168+
func returnLastUpdatesGasStation(values *[]gsmodel.GasPrice) []gsmodel.GasPrice {
169+
var myGasPrices []gsmodel.GasPrice
170+
gasPriceUpdateMap := make(map[string]gsmodel.GasPrice)
171+
for _, value := range *values {
172+
if entry, ok := gasPriceUpdateMap[value.GasStationID]; ok {
173+
if entry.Date.Before(value.Date) {
174+
gasPriceUpdateMap[value.GasStationID] = value
175+
}
176+
} else {
177+
gasPriceUpdateMap[value.GasStationID] = value
178+
}
179+
}
180+
for _, value := range gasPriceUpdateMap {
181+
myGasPrices = append(myGasPrices, value)
182+
}
183+
return myGasPrices
184+
}
185+
166186
func createNewGasStation(value GasStationImport) gsmodel.GasStation {
167187
var resultGs gsmodel.GasStation
168188
resultGs.ID = value.Uuid
@@ -305,9 +325,9 @@ func sendNotifications(gasStationIDToGasPriceMap *map[string]gsmodel.GasPrice) {
305325
}
306326

307327
func createInChunks(ids *[]string, chunkedSelects bool) [][]string {
308-
chunkSize := 1000
328+
chunkSize := 500
309329
if chunkedSelects {
310-
chunkSize = 399
330+
chunkSize = 249
311331
}
312332
chuncks := chunkSlice(*ids, chunkSize)
313333
if len(chuncks) > 1 {

0 commit comments

Comments
 (0)