Skip to content

Commit

Permalink
add account.pool-size config option
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Sep 25, 2024
1 parent 0584c03 commit 358cbcc
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 78 deletions.
95 changes: 32 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 39 additions & 15 deletions src/account/command/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,45 @@ impl SynchronizeAccountCommand {
.with_prebuilt_credentials()
.await?;
let left = BackendBuilder::new(left_config.clone(), left_ctx);
self.pre_sync(printer, name.as_str(), left, right_config, right_backend)
.await
self.pre_sync(
printer,
name.as_str(),
config.pool_size,
left,
right_config,
right_backend,
)
.await
}
#[cfg(feature = "maildir")]
BackendConfig::Maildir(maildir_config) => {
let left_ctx =
MaildirContextBuilder::new(left_config.clone(), Arc::new(maildir_config));
let left = BackendBuilder::new(left_config.clone(), left_ctx);
self.pre_sync(printer, name.as_str(), left, right_config, right_backend)
.await
self.pre_sync(
printer,
name.as_str(),
config.pool_size,
left,
right_config,
right_backend,
)
.await
}
#[cfg(feature = "notmuch")]
BackendConfig::Notmuch(notmuch_config) => {
let left_ctx =
NotmuchContextBuilder::new(left_config.clone(), Arc::new(notmuch_config));
let left = BackendBuilder::new(left_config.clone(), left_ctx);
self.pre_sync(printer, name.as_str(), left, right_config, right_backend)
.await
self.pre_sync(
printer,
name.as_str(),
config.pool_size,
left,
right_config,
right_backend,
)
.await
}
}
}
Expand All @@ -145,6 +166,7 @@ impl SynchronizeAccountCommand {
self,
printer: &mut impl Printer,
account_name: &str,
pool_size: Option<usize>,
left: BackendBuilder<impl BackendContextBuilder + SyncHash + 'static>,
right_config: Arc<AccountConfig>,
right_backend: BackendConfig,
Expand All @@ -160,21 +182,24 @@ impl SynchronizeAccountCommand {
.with_prebuilt_credentials()
.await?;
let right = BackendBuilder::new(right_config.clone(), right_ctx);
self.sync(printer, account_name, left, right).await
self.sync(printer, account_name, pool_size, left, right)
.await
}
#[cfg(feature = "maildir")]
BackendConfig::Maildir(maildir_config) => {
let right_ctx =
MaildirContextBuilder::new(right_config.clone(), Arc::new(maildir_config));
let right = BackendBuilder::new(right_config.clone(), right_ctx);
self.sync(printer, account_name, left, right).await
self.sync(printer, account_name, pool_size, left, right)
.await
}
#[cfg(feature = "notmuch")]
BackendConfig::Notmuch(notmuch_config) => {
let right_ctx =
NotmuchContextBuilder::new(right_config.clone(), Arc::new(notmuch_config));
let right = BackendBuilder::new(right_config.clone(), right_ctx);
self.sync(printer, account_name, left, right).await
self.sync(printer, account_name, pool_size, left, right)
.await
}
}
}
Expand All @@ -183,6 +208,7 @@ impl SynchronizeAccountCommand {
self,
printer: &mut impl Printer,
account_name: &str,
pool_size: Option<usize>,
left: BackendBuilder<impl BackendContextBuilder + SyncHash + 'static>,
right: BackendBuilder<impl BackendContextBuilder + SyncHash + 'static>,
) -> Result<()> {
Expand All @@ -199,14 +225,12 @@ impl SynchronizeAccountCommand {
None
};

let sync_builder = SyncBuilder::new(left, right).with_some_folder_filters(folders_filter);
let sync_builder = SyncBuilder::new(left, right)
.with_some_pool_size(pool_size)
.with_some_folder_filters(folders_filter);

if self.dry_run {
let report = sync_builder
.with_dry_run(true)
.with_pool_size(1)
.sync()
.await?;
let report = sync_builder.with_dry_run(true).sync().await?;
let mut hunks_count = report.folder.patch.len();

if !report.folder.patch.is_empty() {
Expand Down
6 changes: 6 additions & 0 deletions src/account/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub struct AccountConfig {
/// that there is not implicit difference between source and
/// target. Hence left and right are used instead.
pub right: BackendGlobalConfig,

/// The size of the connection pool.
///
/// Mostly used by the IMAP backend, but may be used by other
/// backends in the future.
pub pool_size: Option<usize>,
}

impl AccountConfig {
Expand Down
1 change: 1 addition & 0 deletions src/account/wizard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub async fn configure() -> Result<(String, AccountConfig)> {
envelope: None,
left: backend::wizard::configure(&name, BackendSource::Left).await?,
right: backend::wizard::configure(&name, BackendSource::Right).await?,
pool_size: None,
};

Ok((name, config))
Expand Down

0 comments on commit 358cbcc

Please sign in to comment.