public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager] ui: resource tree: use AsyncPool to cancel obsolete pending loads
Date: Wed, 16 Apr 2025 13:32:32 +0200	[thread overview]
Message-ID: <20250416113232.2488103-1-d.csapak@proxmox.com> (raw)

Currently, if a new serach term is given, a new load will occur if the
INPUT_BUFFER_MS time is reached. Any old in-flight API requests are not
canceled, and might still arrive.

To prevent that, use an AsyncPool and refresh that when the search term
changes.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/widget/resource_tree.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ui/src/widget/resource_tree.rs b/ui/src/widget/resource_tree.rs
index feff308..4db80a8 100644
--- a/ui/src/widget/resource_tree.rs
+++ b/ui/src/widget/resource_tree.rs
@@ -18,6 +18,7 @@ use pwt::{
         },
         ActionIcon, Column, Container, Fa, Panel, Progress, Row, Tooltip,
     },
+    AsyncPool,
 };
 use pwt_macros::{builder, widget};
 
@@ -101,6 +102,7 @@ pub struct PdmResourceTree {
     _context_listener: ContextHandle<RemoteList>,
     selection: Selection,
     _load_timeout: Option<Timeout>,
+    async_pool: AsyncPool,
 }
 
 impl PdmResourceTree {}
@@ -131,6 +133,7 @@ impl Component for PdmResourceTree {
             _context_listener,
             selection,
             _load_timeout: None,
+            async_pool: AsyncPool::new(),
         }
     }
 
@@ -140,9 +143,10 @@ impl Component for PdmResourceTree {
                 let props = ctx.props();
                 let link = ctx.link().clone();
                 let search_term = props.search_term.clone();
+                let async_pool = self.async_pool.clone();
                 if props.search_only && !search_term.is_empty() {
                     self._load_timeout = Some(Timeout::new(INPUT_BUFFER_MS, move || {
-                        link.send_future(async move {
+                        async_pool.send_future(link, async move {
                             Msg::LoadResult(load_resources(search_term).await)
                         });
                     }));
@@ -200,6 +204,8 @@ impl Component for PdmResourceTree {
         let props = ctx.props();
         if props.search_term != old_props.search_term {
             if !props.search_only || !props.search_term.is_empty() {
+                // cancel old pending loads
+                self.async_pool = AsyncPool::new();
                 ctx.link().clone().send_message(Msg::Load);
             } else if props.search_term.is_empty() {
                 // clear grid
-- 
2.39.5



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


             reply	other threads:[~2025-04-16 11:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-16 11:32 Dominik Csapak [this message]
2025-04-17 15:43 ` Thomas Lamprecht
2025-04-18  6:10   ` Dominik Csapak
2025-04-18  7:29     ` Dominik Csapak
2025-04-18  7:47 ` Dominik Csapak

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=20250416113232.2488103-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal