pinakes-core: add batch_update_media; RAII temp file cleanup in import
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Icdec2d385c11ec64622611f3be09a20f6a6a6964
This commit is contained in:
parent
cd63eeccff
commit
237f7c28d2
2 changed files with 28 additions and 45 deletions
|
|
@ -403,32 +403,42 @@ pub async fn import_directory_with_options(
|
|||
|
||||
// Limit concurrency by draining when we hit the cap
|
||||
if join_set.len() >= concurrency
|
||||
&& let Some(Ok((path, result))) = join_set.join_next().await
|
||||
&& let Some(result) = join_set.join_next().await
|
||||
{
|
||||
match result {
|
||||
Ok(r) => results.push(Ok(r)),
|
||||
Err(e) => {
|
||||
tracing::warn!(path = %path.display(), error = %e, "failed to import file");
|
||||
results.push(Err(e));
|
||||
},
|
||||
}
|
||||
collect_import_result(result, &mut results);
|
||||
}
|
||||
}
|
||||
|
||||
// Drain remaining tasks
|
||||
while let Some(Ok((path, result))) = join_set.join_next().await {
|
||||
match result {
|
||||
Ok(r) => results.push(Ok(r)),
|
||||
Err(e) => {
|
||||
tracing::warn!(path = %path.display(), error = %e, "failed to import file");
|
||||
results.push(Err(e));
|
||||
},
|
||||
}
|
||||
while let Some(result) = join_set.join_next().await {
|
||||
collect_import_result(result, &mut results);
|
||||
}
|
||||
|
||||
Ok(results)
|
||||
}
|
||||
|
||||
fn collect_import_result(
|
||||
join_result: std::result::Result<
|
||||
(PathBuf, Result<ImportResult>),
|
||||
tokio::task::JoinError,
|
||||
>,
|
||||
results: &mut Vec<std::result::Result<ImportResult, PinakesError>>,
|
||||
) {
|
||||
match join_result {
|
||||
Ok((_path, Ok(r))) => results.push(Ok(r)),
|
||||
Ok((path, Err(e))) => {
|
||||
tracing::warn!(path = %path.display(), error = %e, "failed to import file");
|
||||
results.push(Err(e));
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::error!(error = %e, "import task panicked");
|
||||
results.push(Err(PinakesError::InvalidOperation(format!(
|
||||
"import task panicked: {e}"
|
||||
))));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract markdown links from a file and store them in the database.
|
||||
async fn extract_and_store_links(
|
||||
storage: &DynStorageBackend,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue