update_from_content: write sides to backend concurrently

This commit is contained in:
Martin von Zweigbergk 2025-04-19 21:50:27 -07:00
parent 7073811fe0
commit 382cedc114
No known key found for this signature in database

View File

@ -21,6 +21,7 @@ use std::iter::zip;
use bstr::BString; use bstr::BString;
use bstr::ByteSlice as _; use bstr::ByteSlice as _;
use futures::future::try_join_all;
use futures::stream::BoxStream; use futures::stream::BoxStream;
use futures::try_join; use futures::try_join;
use futures::Stream; use futures::Stream;
@ -1017,22 +1018,23 @@ pub async fn update_from_content(
// Now write the new files contents we found by parsing the file with conflict // Now write the new files contents we found by parsing the file with conflict
// markers. // markers.
// TODO: Write these concurrently let new_file_ids: Vec<Option<FileId>> =
let new_file_ids: Vec<Option<FileId>> = zip(contents.iter(), simplified_file_ids.iter()) try_join_all(zip(contents.iter(), simplified_file_ids.iter()).map(
.map(|(content, file_id)| -> BackendResult<Option<FileId>> { async |(content, file_id)| -> BackendResult<Option<FileId>> {
match file_id { match file_id {
Some(_) => { Some(_) => {
let file_id = store.write_file(path, &mut content.as_slice()).block_on()?; let file_id = store.write_file(path, &mut content.as_slice()).await?;
Ok(Some(file_id)) Ok(Some(file_id))
}
None => {
// The missing side of a conflict is still represented by
// the empty string we materialized it as
Ok(None)
}
} }
None => { },
// The missing side of a conflict is still represented by ))
// the empty string we materialized it as .block_on()?;
Ok(None)
}
}
})
.try_collect()?;
// If the conflict was simplified, expand the conflict to the original // If the conflict was simplified, expand the conflict to the original
// number of sides. // number of sides.