public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH datacenter-manager] ui: resource tree: use AsyncPool to cancel obsolete pending loads
@ 2025-04-16 11:32 Dominik Csapak
  2025-04-17 15:43 ` Thomas Lamprecht
  2025-04-18  7:47 ` Dominik Csapak
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Csapak @ 2025-04-16 11:32 UTC (permalink / raw)
  To: pdm-devel

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-18  7:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-16 11:32 [pdm-devel] [PATCH datacenter-manager] ui: resource tree: use AsyncPool to cancel obsolete pending loads Dominik Csapak
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

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