@@ -158,7 +158,7 @@ impl MysqlConnection {
158
158
Ok ( ( ) )
159
159
}
160
160
161
- fn station_exists (
161
+ fn station_exists_in_stations (
162
162
transaction : & mut mysql:: Transaction < ' _ > ,
163
163
changeuuids : & Vec < String > ,
164
164
) -> Result < Vec < String > , Box < dyn std:: error:: Error > > {
@@ -170,7 +170,7 @@ impl MysqlConnection {
170
170
}
171
171
let result = transaction. exec_iter (
172
172
format ! (
173
- "SELECT StationUuid FROM StationHistory WHERE StationUuid IN ({})" ,
173
+ "SELECT StationUuid FROM Station WHERE StationUuid IN ({})" ,
174
174
select_query. join( "," )
175
175
) ,
176
176
select_params,
@@ -184,7 +184,7 @@ impl MysqlConnection {
184
184
Ok ( list_result)
185
185
}
186
186
187
- fn stationchange_exists (
187
+ fn stationchange_exists_in_history (
188
188
transaction : & mut mysql:: Transaction < ' _ > ,
189
189
changeuuids : & Vec < String > ,
190
190
) -> Result < Vec < String > , Box < dyn std:: error:: Error > > {
@@ -219,25 +219,25 @@ impl MysqlConnection {
219
219
. iter ( )
220
220
. map ( |item| item. stationuuid . clone ( ) )
221
221
. collect ( ) ;
222
- let stationexists = MysqlConnection :: station_exists ( transaction, & stationuuids) ?;
222
+ let stationexists = MysqlConnection :: station_exists_in_stations ( transaction, & stationuuids) ?;
223
223
224
224
let changeuuids: Vec < String > = stationchanges
225
225
. iter ( )
226
226
. map ( |item| item. changeuuid . clone ( ) )
227
227
. collect ( ) ;
228
- let changeexists = MysqlConnection :: stationchange_exists ( transaction, & changeuuids) ?;
228
+ let changeexists = MysqlConnection :: stationchange_exists_in_history ( transaction, & changeuuids) ?;
229
229
230
- let mut list_ids = vec ! [ ] ;
230
+ let mut hash_ids : HashSet < String > = HashSet :: new ( ) ;
231
231
let mut list_insert: Vec < & StationChangeItemNew > = vec ! [ ] ;
232
232
let mut list_update: Vec < & StationChangeItemNew > = vec ! [ ] ;
233
233
for station in stationchanges {
234
234
if !changeexists. contains ( & station. changeuuid ) {
235
- list_ids. push ( station. stationuuid . clone ( ) ) ;
236
- if stationexists. contains ( & station. stationuuid ) {
235
+ if stationexists. contains ( & station. stationuuid ) || hash_ids. contains ( & station. stationuuid ) {
237
236
list_update. push ( station) ;
238
237
} else {
239
238
list_insert. push ( station) ;
240
239
}
240
+ hash_ids. insert ( station. stationuuid . clone ( ) ) ;
241
241
}
242
242
}
243
243
@@ -301,8 +301,7 @@ impl MysqlConnection {
301
301
"stationuuid" => & change. stationuuid,
302
302
} ) ) ?;
303
303
}
304
-
305
- Ok ( list_ids)
304
+ Ok ( hash_ids. into_iter ( ) . collect ( ) )
306
305
}
307
306
}
308
307
@@ -1459,7 +1458,7 @@ impl DbConnection for MysqlConnection {
1459
1458
list_station_changes,
1460
1459
) ?;
1461
1460
MysqlConnection :: backup_stations_by_uuid ( & mut transaction, & list_ids, source) ?;
1462
-
1461
+
1463
1462
transaction. commit ( ) ?;
1464
1463
Ok ( list_ids)
1465
1464
}
0 commit comments