Skip to content

Commit

Permalink
Allow configuring interval between commits to index (#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
bingryan committed Feb 28, 2024
1 parent e5f48e6 commit f3df93f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'index> Updater<'index> {

uncommitted += 1;

if uncommitted == 5000 {
if uncommitted == self.index.settings.commit_interval {
self.commit(wtx, value_cache)?;
value_cache = HashMap::new();
uncommitted = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ pub struct Options {
help = "Set index cache to <DB_CACHE_SIZE> bytes. By default takes 1/4 of available RAM."
)]
pub(crate) db_cache_size: Option<usize>,
#[arg(
long,
default_value = "5000",
help = "Commit to index every <COMMIT_INTERVAL> blocks."
)]
pub(crate) commit_interval: usize,
#[arg(
long,
help = "Don't look for inscriptions below <FIRST_INSCRIPTION_HEIGHT>."
Expand Down
9 changes: 9 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Settings {
pub(crate) credentials: Option<(String, String)>,
pub(crate) data_dir: PathBuf,
pub(crate) db_cache_size: Option<usize>,
pub(crate) commit_interval: usize,
pub(crate) first_inscription_height: Option<u32>,
pub(crate) height_limit: Option<u32>,
pub(crate) hidden: HashSet<InscriptionId>,
Expand Down Expand Up @@ -86,6 +87,7 @@ impl Settings {
credentials: options.username.zip(options.password),
data_dir: options.data_dir,
db_cache_size: options.db_cache_size,
commit_interval: options.commit_interval,
first_inscription_height: options.first_inscription_height,
height_limit: options.height_limit,
hidden: config.hidden.unwrap_or_default(),
Expand Down Expand Up @@ -851,6 +853,13 @@ mod tests {
assert_eq!(arguments.options.db_cache_size, Some(16000000000));
}

#[test]
fn setting_commit_interval() {
let arguments =
Arguments::try_parse_from(["ord", "--commit-interval", "500", "index", "update"]).unwrap();
assert_eq!(arguments.options.commit_interval, 500);
}

#[test]
fn index_runes_only_returns_true_if_index_runes_flag_is_passed_and_not_on_mainnnet() {
assert!(Arguments::try_parse_from([
Expand Down

0 comments on commit f3df93f

Please sign in to comment.