From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 07E3C1FF183 for ; Wed, 3 Dec 2025 15:34:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 43BC2CAB7; Wed, 3 Dec 2025 15:35:15 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Wed, 3 Dec 2025 15:34:31 +0100 Message-ID: <20251203143439.3595966-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH datacenter-manager 1/2] server: api: subscription: improve cache and update behavior X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" To avoid long load times in the ui, use only cached entries for subscription info in the GET subscription api call by default, but add a 'force-load' parameter to restore the previous behavior. The check_subscription api call now always load from all remotes to get the most up-to-date information from them. Signed-off-by: Dominik Csapak --- server/src/api/nodes/subscription.rs | 16 ++++++++++++---- server/src/api/resources.rs | 5 ++++- .../proxmox-datacenter-manager-daily-update.rs | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server/src/api/nodes/subscription.rs b/server/src/api/nodes/subscription.rs index c84487f0..0ad4c55c 100644 --- a/server/src/api/nodes/subscription.rs +++ b/server/src/api/nodes/subscription.rs @@ -30,12 +30,14 @@ fn apt_auth_file_opts() -> CreateOptions { } async fn get_all_subscription_infos( + max_age: u64, + cache_only: bool, ) -> Result>)>, Error> { let (remotes_config, _digest) = pdm_config::remotes::config()?; let mut subscription_info = HashMap::new(); for (remote_name, remote) in remotes_config.iter() { - match get_subscription_info_for_remote(remote, 24 * 60 * 60).await { + match get_subscription_info_for_remote(remote, max_age, cache_only).await { Ok(info) => { subscription_info.insert(remote_name.to_string(), (remote.ty, info)); } @@ -94,6 +96,12 @@ fn check_counts(stats: &SubscriptionStatistics) -> Result<(), Error> { node: { schema: NODE_SCHEMA, }, + "force-load": { + type: bool, + optional: true, + default: false, + description: "If true, tries to load subscription from remotes that are not cached.", + }, }, }, returns: { @@ -101,8 +109,8 @@ fn check_counts(stats: &SubscriptionStatistics) -> Result<(), Error> { } )] /// Return subscription status -pub async fn get_subscription() -> Result { - let infos = get_all_subscription_infos().await?; +pub async fn get_subscription(force_load: bool) -> Result { + let infos = get_all_subscription_infos(24 * 60 * 60, !force_load).await?; let statistics = count_subscriptions(&infos); @@ -140,7 +148,7 @@ pub async fn get_subscription() -> Result { )] /// Update subscription information pub async fn check_subscription() -> Result<(), Error> { - let infos = get_all_subscription_infos().await?; + let infos = get_all_subscription_infos(0, false).await?; let stats = count_subscriptions(&infos); if let Err(err) = check_counts(&stats) { diff --git a/server/src/api/resources.rs b/server/src/api/resources.rs index c97644ad..7cbdb5b6 100644 --- a/server/src/api/resources.rs +++ b/server/src/api/resources.rs @@ -635,7 +635,7 @@ pub async fn get_subscription_status( let future = async move { let (node_status, error) = - match get_subscription_info_for_remote(&remote, max_age).await { + match get_subscription_info_for_remote(&remote, max_age, false).await { Ok(mut node_status) => { node_status.retain(|node, _| { if let Some(view) = &view { @@ -773,9 +773,12 @@ static SUBSCRIPTION_CACHE: LazyLock Result>, Error> { if let Some(cached_subscription) = get_cached_subscription_info(&remote.id, max_age) { Ok(cached_subscription.node_info) + } else if cache_only { + Ok(HashMap::new()) } else { let node_info = fetch_remote_subscription_info(remote).await?; let now = proxmox_time::epoch_i64(); diff --git a/server/src/bin/proxmox-datacenter-manager-daily-update.rs b/server/src/bin/proxmox-datacenter-manager-daily-update.rs index ad29c2c2..c2dd843c 100644 --- a/server/src/bin/proxmox-datacenter-manager-daily-update.rs +++ b/server/src/bin/proxmox-datacenter-manager-daily-update.rs @@ -26,7 +26,7 @@ async fn do_update(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> { if let Err(err) = &api::nodes::subscription::check_subscription().await { log::error!("Error checking subscription - {err}"); } - match api::nodes::subscription::get_subscription().await { + match api::nodes::subscription::get_subscription(true).await { Ok(info) if info.info.status == SubscriptionStatus::Active => {} Ok(info) => { log::warn!( -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel