@@ -156,13 +156,33 @@ func findPricesByStids(stids *[]string, resultLimit int, timeframe TimeFrame) []
156
156
}
157
157
myQuery .Find (& values )
158
158
//log.Printf("%v", values)
159
- myGasPrices = append (myGasPrices , values ... )
159
+ var lastUpdates = returnLastUpdatesGasStation (& values )
160
+ //log.Printf("%v", lastUpdates)
161
+ myGasPrices = append (myGasPrices , lastUpdates ... )
160
162
}
161
163
return nil
162
164
})
163
165
return myGasPrices
164
166
}
165
167
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
+
166
186
func createNewGasStation (value GasStationImport ) gsmodel.GasStation {
167
187
var resultGs gsmodel.GasStation
168
188
resultGs .ID = value .Uuid
@@ -305,9 +325,9 @@ func sendNotifications(gasStationIDToGasPriceMap *map[string]gsmodel.GasPrice) {
305
325
}
306
326
307
327
func createInChunks (ids * []string , chunkedSelects bool ) [][]string {
308
- chunkSize := 1000
328
+ chunkSize := 500
309
329
if chunkedSelects {
310
- chunkSize = 399
330
+ chunkSize = 249
311
331
}
312
332
chuncks := chunkSlice (* ids , chunkSize )
313
333
if len (chuncks ) > 1 {
0 commit comments