feat(cli): make db stats non-detailed by default (#8056)

This commit is contained in:
Alexey Shekhirin
2024-05-02 20:31:48 +01:00
committed by GitHub
parent 1a1c24ba24
commit 232e7bf19b
14 changed files with 343 additions and 142 deletions

View File

@ -25,11 +25,11 @@ use tracing::info;
pub struct Command {
/// Show only the total size for static files.
#[arg(long, default_value_t = false)]
only_total_size: bool,
detailed_sizes: bool,
/// Show only the summary per static file segment.
/// Show detailed information per static file segment.
#[arg(long, default_value_t = false)]
summary: bool,
detailed_segments: bool,
/// Show a checksum of each table in the database.
///
@ -152,7 +152,7 @@ impl Command {
let mut table = ComfyTable::new();
table.load_preset(comfy_table::presets::ASCII_MARKDOWN);
if !self.only_total_size {
if self.detailed_sizes {
table.set_header([
"Segment",
"Block Range",
@ -216,7 +216,25 @@ impl Command {
.map(|metadata| metadata.len())
.unwrap_or_default();
if self.summary {
if self.detailed_segments {
let mut row = Row::new();
row.add_cell(Cell::new(segment))
.add_cell(Cell::new(format!("{block_range}")))
.add_cell(Cell::new(
tx_range.map_or("N/A".to_string(), |tx_range| format!("{tx_range}")),
))
.add_cell(Cell::new(format!("{columns} x {rows}")));
if self.detailed_sizes {
row.add_cell(Cell::new(human_bytes(data_size as f64)))
.add_cell(Cell::new(human_bytes(index_size as f64)))
.add_cell(Cell::new(human_bytes(offsets_size as f64)))
.add_cell(Cell::new(human_bytes(config_size as f64)));
}
row.add_cell(Cell::new(human_bytes(
(data_size + index_size + offsets_size + config_size) as f64,
)));
table.add_row(row);
} else {
if segment_columns > 0 {
assert_eq!(segment_columns, columns);
} else {
@ -227,24 +245,6 @@ impl Command {
segment_index_size += index_size;
segment_offsets_size += offsets_size;
segment_config_size += config_size;
} else {
let mut row = Row::new();
row.add_cell(Cell::new(segment))
.add_cell(Cell::new(format!("{block_range}")))
.add_cell(Cell::new(
tx_range.map_or("N/A".to_string(), |tx_range| format!("{tx_range}")),
))
.add_cell(Cell::new(format!("{columns} x {rows}")));
if !self.only_total_size {
row.add_cell(Cell::new(human_bytes(data_size as f64)))
.add_cell(Cell::new(human_bytes(index_size as f64)))
.add_cell(Cell::new(human_bytes(offsets_size as f64)))
.add_cell(Cell::new(human_bytes(config_size as f64)));
}
row.add_cell(Cell::new(human_bytes(
(data_size + index_size + offsets_size + config_size) as f64,
)));
table.add_row(row);
}
total_data_size += data_size;
@ -253,7 +253,7 @@ impl Command {
total_config_size += config_size;
}
if self.summary {
if !self.detailed_segments {
let first_ranges = ranges.first().expect("not empty list of ranges");
let last_ranges = ranges.last().expect("not empty list of ranges");
@ -271,7 +271,7 @@ impl Command {
tx_range.map_or("N/A".to_string(), |tx_range| format!("{tx_range}")),
))
.add_cell(Cell::new(format!("{segment_columns} x {segment_rows}")));
if !self.only_total_size {
if self.detailed_sizes {
row.add_cell(Cell::new(human_bytes(segment_data_size as f64)))
.add_cell(Cell::new(human_bytes(segment_index_size as f64)))
.add_cell(Cell::new(human_bytes(segment_offsets_size as f64)))
@ -299,7 +299,7 @@ impl Command {
.add_cell(Cell::new(""))
.add_cell(Cell::new(""))
.add_cell(Cell::new(""));
if !self.only_total_size {
if self.detailed_sizes {
row.add_cell(Cell::new(human_bytes(total_data_size as f64)))
.add_cell(Cell::new(human_bytes(total_index_size as f64)))
.add_cell(Cell::new(human_bytes(total_offsets_size as f64)))