diff --git a/libs/jwst-storage/src/storage/blobs/local_db.rs b/libs/jwst-storage/src/storage/blobs/local_db.rs index 78e2044a..538fbace 100644 --- a/libs/jwst-storage/src/storage/blobs/local_db.rs +++ b/libs/jwst-storage/src/storage/blobs/local_db.rs @@ -1,4 +1,5 @@ use jwst::{Base64Engine, URL_SAFE_ENGINE}; +use jwst_storage_migration::Alias; use sha2::{Digest, Sha256}; use super::{utils::get_hash, *}; @@ -79,7 +80,7 @@ impl BlobDBStorage { Blobs::find() .filter(BlobColumn::WorkspaceId.is_in(workspaces)) .select_only() - .column_as(BlobColumn::Length.sum(), "size") + .column_as(BlobColumn::Length.sum().cast_as(Alias::new("bigint")), "size") .into_tuple::>() .one(&self.pool) .await diff --git a/libs/jwst-storage/src/storage/blobs/mod.rs b/libs/jwst-storage/src/storage/blobs/mod.rs index 9380561a..18baef57 100644 --- a/libs/jwst-storage/src/storage/blobs/mod.rs +++ b/libs/jwst-storage/src/storage/blobs/mod.rs @@ -416,6 +416,8 @@ mod tests { let storage = BlobAutoStorage::init_pool("sqlite::memory:").await.unwrap(); Migrator::up(&storage.pool, None).await.unwrap(); + assert_eq!(storage.get_blobs_size(vec!["blob".into()]).await.unwrap(), 0); + let blob = Vec::from_iter((0..100).map(|_| rand::random())); let stream = async { Bytes::from(blob.clone()) }.into_stream(); @@ -437,6 +439,10 @@ mod tests { .size as usize, blob.len() ); + assert_eq!( + storage.get_blobs_size(vec!["blob".into()]).await.unwrap(), + blob.len() as i64 + ); // optimize must failed if blob not supported assert!(storage @@ -554,8 +560,8 @@ mod tests { .is_err()); assert_eq!( - storage.get_blobs_size(vec!["blob".into()]).await.unwrap() as usize, - 100 + image.len() + storage.get_blobs_size(vec!["blob".into()]).await.unwrap(), + (blob.len() + image.len()) as i64 ); assert!(storage.delete_blob(Some("blob".into()), hash2.clone()).await.unwrap()); @@ -583,5 +589,32 @@ mod tests { storage.list_blobs(Some("not_exists_workspace".into())).await.unwrap(), Vec::::new() ); + + { + let blob = Vec::from_iter((0..100).map(|_| rand::random())); + let stream = async { Bytes::from(blob.clone()) }.into_stream(); + storage.put_blob_stream(Some("blob1".into()), stream).await.unwrap(); + + assert_eq!( + storage + .get_blobs_size(vec!["blob".into(), "blob1".into()]) + .await + .unwrap() as usize, + 200 + ); + } + + // test calc with not exists workspaces + { + assert_eq!( + storage + .get_blobs_size(vec!["blob".into(), "blob1".into(), "blob2".into()]) + .await + .unwrap(), + 200 + ); + + assert_eq!(storage.get_blobs_size(vec!["blob2".into()]).await.unwrap(), 0); + } } }