Skip to content

Commit

Permalink
refactor: display sizes in a human readable format
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Feb 3, 2025
1 parent b7b79cf commit 63bc3bf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion mithril-client-cli/src/commands/cardano_db/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use cli_table::{format::Justify, print_stdout, Cell, Table};

use crate::{
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
utils::CardanoDbUtils,
CommandContext,
};
use mithril_client::MithrilResult;
Expand Down Expand Up @@ -39,7 +40,7 @@ impl CardanoDbListCommand {
format!("{}", item.beacon.immutable_file_number).cell(),
item.network.cell(),
item.digest.cell(),
item.size.cell(),
CardanoDbUtils::format_bytes_to_gigabytes(item.size).cell(),
format!("{}", item.locations.len()).cell(),
item.created_at.to_string().cell(),
]
Expand Down
4 changes: 2 additions & 2 deletions mithril-client-cli/src/commands/cardano_db/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cli_table::{print_stdout, Cell, Table};

use crate::{
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
utils::ExpanderUtils,
utils::{CardanoDbUtils, ExpanderUtils},
CommandContext,
};
use mithril_client::MithrilResult;
Expand Down Expand Up @@ -70,7 +70,7 @@ impl CardanoDbShowCommand {
vec!["Digest".cell(), cardano_db_message.digest.cell()],
vec![
"Size".cell(),
format!("{}", &cardano_db_message.size).cell(),
CardanoDbUtils::format_bytes_to_gigabytes(cardano_db_message.size).cell(),
],
vec![
"Cardano node version".cell(),
Expand Down
4 changes: 3 additions & 1 deletion mithril-client-cli/src/commands/cardano_db_v2/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use mithril_client::MithrilResult;

use crate::{
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
utils::CardanoDbUtils,
CommandContext,
};

Expand Down Expand Up @@ -40,7 +41,8 @@ impl CardanoDbListCommand {
format!("{}", item.beacon.immutable_file_number).cell(),
item.hash.cell(),
item.merkle_root.cell(),
item.total_db_size_uncompressed.cell(),
CardanoDbUtils::format_bytes_to_gigabytes(item.total_db_size_uncompressed)
.cell(),
format!("{}", item.compression_algorithm).cell(),
item.cardano_node_version.cell(),
item.created_at.to_string().cell(),
Expand Down
7 changes: 5 additions & 2 deletions mithril-client-cli/src/commands/cardano_db_v2/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cli_table::{print_stdout, Cell, CellStruct, Table};

use crate::{
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
utils::ExpanderUtils,
utils::{CardanoDbUtils, ExpanderUtils},
CommandContext,
};

Expand Down Expand Up @@ -78,7 +78,10 @@ impl CardanoDbShowCommand {
vec!["Merkle root".cell(), cardano_db_message.merkle_root.cell()],
vec![
"Database size".cell(),
format!("{}", &cardano_db_message.total_db_size_uncompressed).cell(),
CardanoDbUtils::format_bytes_to_gigabytes(
cardano_db_message.total_db_size_uncompressed,
)
.cell(),
],
vec![
"Cardano node version".cell(),
Expand Down
6 changes: 6 additions & 0 deletions mithril-client-cli/src/utils/cardano_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl CardanoDbUtils {
res = future => res,
}
}

pub fn format_bytes_to_gigabytes(bytes: u64) -> String {
let size_in_giga = bytes as f64 / (1024.0 * 1024.0 * 1024.0);

format!("{:.2} GB", size_in_giga)
}
}

#[cfg(test)]
Expand Down

0 comments on commit 63bc3bf

Please sign in to comment.