From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 1/2] server: api: subscription: improve cache and update behavior
Date: Wed, 3 Dec 2025 15:34:31 +0100 [thread overview]
Message-ID: <20251203143439.3595966-1-d.csapak@proxmox.com> (raw)
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 <d.csapak@proxmox.com>
---
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<HashMap<String, (RemoteType, HashMap<String, Option<NodeSubscriptionInfo>>)>, 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<PdmSubscriptionInfo, Error> {
- let infos = get_all_subscription_infos().await?;
+pub async fn get_subscription(force_load: bool) -> Result<PdmSubscriptionInfo, Error> {
+ 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<PdmSubscriptionInfo, Error> {
)]
/// 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<RwLock<HashMap<String, CachedSubscriptionSta
pub async fn get_subscription_info_for_remote(
remote: &Remote,
max_age: u64,
+ cache_only: bool,
) -> Result<HashMap<String, Option<NodeSubscriptionInfo>>, 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
next reply other threads:[~2025-12-03 14:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-03 14:34 Dominik Csapak [this message]
2025-12-03 14:34 ` [pdm-devel] [PATCH datacenter-manager 2/2] ui: subscription: use 'force-load' parameter Dominik Csapak
2025-12-03 20:47 ` [pdm-devel] [PATCH datacenter-manager 1/2] server: api: subscription: improve cache and update behavior Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251203143439.3595966-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox