mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Properly sync associated items of recordings and works
This commit is contained in:
parent
bec0dfbf56
commit
37f21c582d
7 changed files with 103 additions and 89 deletions
|
|
@ -115,6 +115,34 @@ impl Database {
|
|||
let recording_id = &recording.id;
|
||||
self.delete_recording(recording_id)?;
|
||||
|
||||
// Add associated items from the server, if they don't already exist.
|
||||
|
||||
if self.get_work(&recording.work.id)?.is_none() {
|
||||
self.update_work(recording.work.clone())?;
|
||||
}
|
||||
|
||||
for performance in &recording.performances {
|
||||
if let Some(person) = &performance.person {
|
||||
if self.get_person(&person.id)?.is_none() {
|
||||
self.update_person(person.clone())?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ensemble) = &performance.ensemble {
|
||||
if self.get_ensemble(&ensemble.id)?.is_none() {
|
||||
self.update_ensemble(ensemble.clone())?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(role) = &performance.role {
|
||||
if self.get_instrument(&role.id)?.is_none() {
|
||||
self.update_instrument(role.clone())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the actual recording.
|
||||
|
||||
let row: RecordingRow = recording.clone().into();
|
||||
diesel::insert_into(recordings::table)
|
||||
.values(row)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue