Skip to content
This repository was archived by the owner on Oct 8, 2023. It is now read-only.

Commit 050b857

Browse files
author
Alex
committed
pull: insert duplicates fix
1 parent ed77d69 commit 050b857

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
## [0.7.22] 2021-11-10
1010
### Fixed
1111
* CHECK: check for http result code for favicons
12+
* PULL: insert duplicates
1213

1314
## [0.7.21] 2021-11-09
1415
### Added

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "Radio-Browser Server with REST API"
44
license = "agpl-3.0"
55
name = "radiobrowser-api-rust"
66
readme = "README.md"
7-
version = "0.7.21"
7+
version = "0.7.22"
88
edition = "2021"
99

1010
[dependencies]

src/db/db_mysql/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl MysqlConnection {
158158
Ok(())
159159
}
160160

161-
fn station_exists(
161+
fn station_exists_in_stations(
162162
transaction: &mut mysql::Transaction<'_>,
163163
changeuuids: &Vec<String>,
164164
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
@@ -170,7 +170,7 @@ impl MysqlConnection {
170170
}
171171
let result = transaction.exec_iter(
172172
format!(
173-
"SELECT StationUuid FROM StationHistory WHERE StationUuid IN ({})",
173+
"SELECT StationUuid FROM Station WHERE StationUuid IN ({})",
174174
select_query.join(",")
175175
),
176176
select_params,
@@ -184,7 +184,7 @@ impl MysqlConnection {
184184
Ok(list_result)
185185
}
186186

187-
fn stationchange_exists(
187+
fn stationchange_exists_in_history(
188188
transaction: &mut mysql::Transaction<'_>,
189189
changeuuids: &Vec<String>,
190190
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
@@ -219,25 +219,25 @@ impl MysqlConnection {
219219
.iter()
220220
.map(|item| item.stationuuid.clone())
221221
.collect();
222-
let stationexists = MysqlConnection::station_exists(transaction, &stationuuids)?;
222+
let stationexists = MysqlConnection::station_exists_in_stations(transaction, &stationuuids)?;
223223

224224
let changeuuids: Vec<String> = stationchanges
225225
.iter()
226226
.map(|item| item.changeuuid.clone())
227227
.collect();
228-
let changeexists = MysqlConnection::stationchange_exists(transaction, &changeuuids)?;
228+
let changeexists = MysqlConnection::stationchange_exists_in_history(transaction, &changeuuids)?;
229229

230-
let mut list_ids = vec![];
230+
let mut hash_ids: HashSet<String> = HashSet::new();
231231
let mut list_insert: Vec<&StationChangeItemNew> = vec![];
232232
let mut list_update: Vec<&StationChangeItemNew> = vec![];
233233
for station in stationchanges {
234234
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) {
237236
list_update.push(station);
238237
}else{
239238
list_insert.push(station);
240239
}
240+
hash_ids.insert(station.stationuuid.clone());
241241
}
242242
}
243243

@@ -301,8 +301,7 @@ impl MysqlConnection {
301301
"stationuuid" => &change.stationuuid,
302302
}))?;
303303
}
304-
305-
Ok(list_ids)
304+
Ok(hash_ids.into_iter().collect())
306305
}
307306
}
308307

@@ -1459,7 +1458,7 @@ impl DbConnection for MysqlConnection {
14591458
list_station_changes,
14601459
)?;
14611460
MysqlConnection::backup_stations_by_uuid(&mut transaction, &list_ids, source)?;
1462-
1461+
14631462
transaction.commit()?;
14641463
Ok(list_ids)
14651464
}

0 commit comments

Comments
 (0)