about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-11-07 11:44:06 +0300
committerVika <vika@fireburn.ru>2022-11-07 11:44:06 +0300
commita3d354fc5f5f3dc7249d24498973259738bae83a (patch)
treea1e6a2ec6bcf8f1109561121a688c2ba14bfebf5
parent2ffa3c0d155baa0e5292647eea47d6aa002ad7c1 (diff)
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.
-rw-r--r--kittybox-rs/src/media/storage/file.rs14
1 files changed, 9 insertions, 5 deletions
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 || {