mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-04 15:02:16 +02:00
feat: sort alias accounts descending and fixed sorting for csv batch (#573)
sort alias accounts descending and fixed sorting for csv batch (#573)
This commit is contained in:
@@ -1142,21 +1142,21 @@ fn collect_accounts(input: &ConfigInput) -> Vec<AccountCredentials> {
|
||||
}
|
||||
|
||||
fn compare_alias_exp_date(a: &ConfigInputAliasDto, b: &ConfigInputAliasDto) -> Ordering {
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MAX);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MAX);
|
||||
a_ts.cmp(&b_ts).then_with(|| a.name.cmp(&b.name))
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MIN);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MIN);
|
||||
b_ts.cmp(&a_ts).then_with(|| a.name.cmp(&b.name))
|
||||
}
|
||||
|
||||
fn compare_alias_exp_date_config(a: &ConfigInputAlias, b: &ConfigInputAlias) -> Ordering {
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MAX);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MAX);
|
||||
a_ts.cmp(&b_ts).then_with(|| a.name.cmp(&b.name))
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MIN);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MIN);
|
||||
b_ts.cmp(&a_ts).then_with(|| a.name.cmp(&b.name))
|
||||
}
|
||||
|
||||
fn compare_account_exp_date(a: &AccountCredentials, b: &AccountCredentials) -> Ordering {
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MAX);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MAX);
|
||||
a_ts.cmp(&b_ts).then_with(|| a.name.cmp(&b.name))
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MIN);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MIN);
|
||||
b_ts.cmp(&a_ts).then_with(|| a.name.cmp(&b.name))
|
||||
}
|
||||
|
||||
fn aliases_need_sort_config(aliases: &[ConfigInputAlias]) -> bool {
|
||||
@@ -2439,28 +2439,17 @@ async fn sync_panel_api_for_input_on_boot(
|
||||
let mut time_cache = load_panel_api_time_cache(app_state.as_ref(), &cache_path).await;
|
||||
let cached_entry = time_cache.inputs.get(input.name.as_ref()).cloned();
|
||||
|
||||
if panel_cfg.alias_pool.is_some() {
|
||||
if let Some(csv_path) = csv_path.as_ref() {
|
||||
let _csv_lock = app_state.app_config.file_locks.write_lock(csv_path).await;
|
||||
match csv_patch_batch_sort_by_exp_date(input.input_type, csv_path).await {
|
||||
Ok(true) => any_change = true,
|
||||
Ok(false) => {}
|
||||
Err(err) => debug_if_enabled!(
|
||||
"panel_api boot/update failed to sort csv alias pool for {}: {}",
|
||||
sanitize_sensitive_info(&input.name),
|
||||
err
|
||||
),
|
||||
}
|
||||
} else if input
|
||||
if panel_cfg.alias_pool.is_some()
|
||||
&& csv_path.is_none()
|
||||
&& input
|
||||
.aliases
|
||||
.as_ref()
|
||||
.is_some_and(|aliases| aliases_need_sort_config(aliases))
|
||||
{
|
||||
sources_yml_patches.push(SourcesYmlPatch::SortAliases {
|
||||
input_name: input.name.clone(),
|
||||
});
|
||||
pending_sources_yml = true;
|
||||
}
|
||||
{
|
||||
sources_yml_patches.push(SourcesYmlPatch::SortAliases {
|
||||
input_name: input.name.clone(),
|
||||
});
|
||||
pending_sources_yml = true;
|
||||
}
|
||||
|
||||
if let Some((root_username, root_password)) = extract_account_creds_from_input(input.as_ref()) {
|
||||
@@ -3631,6 +3620,21 @@ async fn sync_panel_api_for_input_on_boot(
|
||||
}
|
||||
}
|
||||
|
||||
if panel_cfg.alias_pool.is_some() {
|
||||
if let Some(csv_path) = csv_path.as_ref() {
|
||||
let _csv_lock = app_state.app_config.file_locks.write_lock(csv_path).await;
|
||||
match csv_patch_batch_sort_by_exp_date(input.input_type, csv_path).await {
|
||||
Ok(true) => any_change = true,
|
||||
Ok(false) => {}
|
||||
Err(err) => debug_if_enabled!(
|
||||
"panel_api boot/update final sort failed for csv alias pool {}: {}",
|
||||
sanitize_sensitive_info(&input.name),
|
||||
err
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if pending_sources_yml {
|
||||
let _src_lock = app_state
|
||||
.app_config
|
||||
|
||||
@@ -554,9 +554,9 @@ pub async fn csv_patch_batch_sort_by_exp_date(
|
||||
}
|
||||
let mut sorted = aliases.clone();
|
||||
sorted.sort_by(|a, b| {
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MAX);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MAX);
|
||||
a_ts.cmp(&b_ts).then_with(|| a.name.cmp(&b.name))
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MIN);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MIN);
|
||||
b_ts.cmp(&a_ts).then_with(|| a.name.cmp(&b.name))
|
||||
});
|
||||
if sorted == aliases {
|
||||
return Ok(false);
|
||||
|
||||
@@ -527,9 +527,9 @@ pub async fn persist_source_config(
|
||||
{
|
||||
if let Some(aliases) = input.aliases.as_mut() {
|
||||
aliases.sort_by(|a, b| {
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MAX);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MAX);
|
||||
a_ts.cmp(&b_ts).then_with(|| a.name.cmp(&b.name))
|
||||
let a_ts = a.exp_date.unwrap_or(i64::MIN);
|
||||
let b_ts = b.exp_date.unwrap_or(i64::MIN);
|
||||
b_ts.cmp(&a_ts).then_with(|| a.name.cmp(&b.name))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user