From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 45E921FF172 for <inbox@lore.proxmox.com>; Wed, 16 Apr 2025 13:32:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CABC934771; Wed, 16 Apr 2025 13:32:35 +0200 (CEST) From: Dominik Csapak <d.csapak@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Wed, 16 Apr 2025 13:32:32 +0200 Message-Id: <20250416113232.2488103-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 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 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] ui: resource tree: use AsyncPool to cancel obsolete pending loads X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> 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