small refactoring (#6321)

This commit is contained in:
Thomas Coratger
2024-02-01 15:30:31 +01:00
committed by GitHub
parent a3128ae36d
commit 01d3df30f7
5 changed files with 40 additions and 59 deletions

View File

@@ -1,19 +1,9 @@
use std::{
collections::HashMap,
fmt::Debug,
fs::{self, File},
hash::Hash,
io::Write,
path::{Path, PathBuf},
};
use crate::utils::DbTool;
use clap::Parser;
use crate::{
args::DatabaseArgs,
dirs::{DataDirPath, PlatformPath},
utils::DbTool,
};
use clap::Parser;
use reth_db::{
cursor::DbCursorRO, database::Database, mdbx::DatabaseArguments, open_db_read_only,
table::Table, transaction::DbTx, AccountChangeSet, AccountHistory, AccountsTrie,
@@ -22,6 +12,14 @@ use reth_db::{
PlainStorageState, PruneCheckpoints, Receipts, StorageChangeSet, StorageHistory, StoragesTrie,
SyncStage, SyncStageProgress, Tables, TransactionBlock, Transactions, TxHashNumber, TxSenders,
};
use std::{
collections::HashMap,
fmt::Debug,
fs::{self, File},
hash::Hash,
io::Write,
path::{Path, PathBuf},
};
use tracing::info;
#[derive(Parser, Debug)]

View File

@@ -3,7 +3,7 @@ use super::{
Command, Compression, PerfectHashingFunction,
};
use rand::{seq::SliceRandom, Rng};
use reth_db::{open_db_read_only, snapshot::ReceiptMask};
use reth_db::{mdbx::DatabaseArguments, open_db_read_only, snapshot::ReceiptMask};
use reth_interfaces::db::LogLevel;
use reth_primitives::{
snapshot::{Filters, InclusionFilter},
@@ -13,8 +13,6 @@ use reth_provider::{
providers::SnapshotProvider, BlockNumReader, ProviderError, ProviderFactory, ReceiptProvider,
TransactionsProvider, TransactionsProviderExt,
};
use reth_db::mdbx::DatabaseArguments;
use std::{
path::{Path, PathBuf},
sync::Arc,

View File

@@ -3,7 +3,7 @@ use super::{
Command, Compression, PerfectHashingFunction,
};
use rand::{seq::SliceRandom, Rng};
use reth_db::{open_db_read_only, snapshot::TransactionMask};
use reth_db::{mdbx::DatabaseArguments, open_db_read_only, snapshot::TransactionMask};
use reth_interfaces::db::LogLevel;
use reth_primitives::{
snapshot::{Filters, InclusionFilter},
@@ -13,8 +13,6 @@ use reth_provider::{
providers::SnapshotProvider, BlockNumReader, ProviderError, ProviderFactory,
TransactionsProvider, TransactionsProviderExt,
};
use reth_db::mdbx::DatabaseArguments;
use std::{
path::{Path, PathBuf},
sync::Arc,

View File

@@ -160,32 +160,22 @@ where
/// Move to the next list selection
fn next(&mut self) {
let i = match self.list_state.selected() {
Some(i) => {
if i >= self.entries.len() - 1 {
0
} else {
i + 1
}
}
None => 0,
};
self.list_state.select(Some(i));
self.list_state.select(Some(
self.list_state
.selected()
.map(|i| if i >= self.entries.len() - 1 { 0 } else { i + 1 })
.unwrap_or(0),
));
}
/// Move to the previous list selection
fn previous(&mut self) {
let i = match self.list_state.selected() {
Some(i) => {
if i == 0 {
self.entries.len() - 1
} else {
i - 1
}
}
None => 0,
};
self.list_state.select(Some(i));
self.list_state.select(Some(
self.list_state
.selected()
.map(|i| if i == 0 { self.entries.len() - 1 } else { i - 1 })
.unwrap_or(0),
));
}
fn reset(&mut self) {
@@ -194,22 +184,18 @@ where
/// Fetch the next page of items
fn next_page(&mut self) {
if self.skip + self.count >= self.total_entries {
return
if self.skip + self.count < self.total_entries {
self.skip += self.count;
self.fetch_page();
}
self.skip += self.count;
self.fetch_page();
}
/// Fetch the previous page of items
fn previous_page(&mut self) {
if self.skip == 0 {
return
if self.skip > 0 {
self.skip = self.skip.saturating_sub(self.count);
self.fetch_page();
}
self.skip = self.skip.saturating_sub(self.count);
self.fetch_page();
}
/// Go to a specific page.

View File

@@ -49,15 +49,16 @@ where
T::Key: Decode,
T::Value: Decompress,
{
let key = match kv.0 {
Cow::Borrowed(k) => Decode::decode(k)?,
Cow::Owned(k) => Decode::decode(k)?,
};
let value = match kv.1 {
Cow::Borrowed(v) => Decompress::decompress(v)?,
Cow::Owned(v) => Decompress::decompress_owned(v)?,
};
Ok((key, value))
Ok((
match kv.0 {
Cow::Borrowed(k) => Decode::decode(k)?,
Cow::Owned(k) => Decode::decode(k)?,
},
match kv.1 {
Cow::Borrowed(v) => Decompress::decompress(v)?,
Cow::Owned(v) => Decompress::decompress_owned(v)?,
},
))
}
/// Helper function to decode only a value from a `(key, value)` pair.