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

Commit

Permalink
pull: insert duplicates fix
Browse files Browse the repository at this point in the history
  • Loading branch information
segler-alex committed Nov 10, 2021
1 parent ed77d69 commit 050b857
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.7.22] 2021-11-10
### Fixed
* CHECK: check for http result code for favicons
* PULL: insert duplicates

## [0.7.21] 2021-11-09
### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Radio-Browser Server with REST API"
license = "agpl-3.0"
name = "radiobrowser-api-rust"
readme = "README.md"
version = "0.7.21"
version = "0.7.22"
edition = "2021"

[dependencies]
Expand Down
21 changes: 10 additions & 11 deletions src/db/db_mysql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl MysqlConnection {
Ok(())
}

fn station_exists(
fn station_exists_in_stations(
transaction: &mut mysql::Transaction<'_>,
changeuuids: &Vec<String>,
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
Expand All @@ -170,7 +170,7 @@ impl MysqlConnection {
}
let result = transaction.exec_iter(
format!(
"SELECT StationUuid FROM StationHistory WHERE StationUuid IN ({})",
"SELECT StationUuid FROM Station WHERE StationUuid IN ({})",
select_query.join(",")
),
select_params,
Expand All @@ -184,7 +184,7 @@ impl MysqlConnection {
Ok(list_result)
}

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

let changeuuids: Vec<String> = stationchanges
.iter()
.map(|item| item.changeuuid.clone())
.collect();
let changeexists = MysqlConnection::stationchange_exists(transaction, &changeuuids)?;
let changeexists = MysqlConnection::stationchange_exists_in_history(transaction, &changeuuids)?;

let mut list_ids = vec![];
let mut hash_ids: HashSet<String> = HashSet::new();
let mut list_insert: Vec<&StationChangeItemNew> = vec![];
let mut list_update: Vec<&StationChangeItemNew> = vec![];
for station in stationchanges {
if !changeexists.contains(&station.changeuuid) {
list_ids.push(station.stationuuid.clone());
if stationexists.contains(&station.stationuuid) {
if stationexists.contains(&station.stationuuid) || hash_ids.contains(&station.stationuuid) {
list_update.push(station);
}else{
list_insert.push(station);
}
hash_ids.insert(station.stationuuid.clone());
}
}

Expand Down Expand Up @@ -301,8 +301,7 @@ impl MysqlConnection {
"stationuuid" => &change.stationuuid,
}))?;
}

Ok(list_ids)
Ok(hash_ids.into_iter().collect())
}
}

Expand Down Expand Up @@ -1459,7 +1458,7 @@ impl DbConnection for MysqlConnection {
list_station_changes,
)?;
MysqlConnection::backup_stations_by_uuid(&mut transaction, &list_ids, source)?;

transaction.commit()?;
Ok(list_ids)
}
Expand Down

0 comments on commit 050b857

Please sign in to comment.