Skip to content

Commit

Permalink
fix: type cast
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Sep 1, 2023
1 parent 460376a commit 58f3bbd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion libs/jwst-storage/src/storage/blobs/local_db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use jwst::{Base64Engine, URL_SAFE_ENGINE};
use jwst_storage_migration::Alias;
use sha2::{Digest, Sha256};

use super::{utils::get_hash, *};
Expand Down Expand Up @@ -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::<Option<i64>>()
.one(&self.pool)
.await
Expand Down
37 changes: 35 additions & 2 deletions libs/jwst-storage/src/storage/blobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -583,5 +589,32 @@ mod tests {
storage.list_blobs(Some("not_exists_workspace".into())).await.unwrap(),
Vec::<String>::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);
}
}
}

1 comment on commit 58f3bbd

@vercel
Copy link

@vercel vercel bot commented on 58f3bbd Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.