Fix loading of dump v2 by patching ranking rules inside update settings

This commit is contained in:
Loïc Lecrenier 2022-06-22 15:31:04 +02:00
parent 496a27f4a2
commit 73845f87cf

View File

@ -78,11 +78,17 @@ fn patch_updates(dir: impl AsRef<Path>, path: impl AsRef<Path>) -> anyhow::Resul
let mut output_update_file = NamedTempFile::new_in(&dir)?; let mut output_update_file = NamedTempFile::new_in(&dir)?;
let update_file = File::open(&path)?; let update_file = File::open(&path)?;
let stream = Deserializer::from_reader(update_file).into_iter::<v2::UpdateEntry>(); let updates = Deserializer::from_reader(update_file).into_iter::<serde_json::Value>();
for update_entry in updates {
for update in stream { let mut update_entry = update_entry?;
let update_entry = update?; println!("{:?}", update_entry);
// We first deserialize the dump meta into a serde_json::Value and change
// the custom ranking rules settings from the old format to the new format.
if let Some(ranking_rules) = update_entry.pointer_mut("/update/meta/rankingRules") {
patch_custom_ranking_rules(ranking_rules);
}
let update_entry: v2::UpdateEntry = serde_json::from_value(update_entry)?;
let update_entry = v3::UpdateEntry::from(update_entry); let update_entry = v3::UpdateEntry::from(update_entry);
serde_json::to_writer(&mut output_update_file, &update_entry)?; serde_json::to_writer(&mut output_update_file, &update_entry)?;