From a3d354fc5f5f3dc7249d24498973259738bae83a Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 7 Nov 2022 11:44:06 +0300 Subject: media: get rid of an extraneous Arc over Bytes Bytes buffers are already reference-counted and cheaply clonable; there is no need to wrap them further. --- kittybox-rs/src/media/storage/file.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'kittybox-rs/src/media') diff --git a/kittybox-rs/src/media/storage/file.rs b/kittybox-rs/src/media/storage/file.rs index 824f326..6d7068b 100644 --- a/kittybox-rs/src/media/storage/file.rs +++ b/kittybox-rs/src/media/storage/file.rs @@ -62,17 +62,21 @@ impl MediaStore for FileStore { let mut length: usize = 0; while let Some(chunk) = content.next().await { - // TODO consider getting rid of this Arc as we only need immutable references - // I don't think we quite need refcounting here - let chunk = std::sync::Arc::new(chunk.map_err(|err| MediaStoreError { + let chunk = chunk.map_err(|err| MediaStoreError { kind: ErrorKind::Backend, source: Some(Box::new(err)), msg: "Failed to read a data chunk".to_owned() - })?); + })?; debug!("Read {} bytes from the stream", chunk.len()); length += chunk.len(); let (write_result, _hasher) = tokio::join!( - tempfile.write_all(&*chunk), + { + let chunk = chunk.clone(); + let tempfile = &mut tempfile; + async move { + tempfile.write_all(&*chunk).await + } + }, { let chunk = chunk.clone(); tokio::task::spawn_blocking(move || { -- cgit 1.4.1