From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-comp 2/2] tasks: don't add entries we already loaded
Date: Wed, 7 May 2025 16:38:00 +0200 [thread overview]
Message-ID: <20250507143800.3461963-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250507143800.3461963-1-d.csapak@proxmox.com>
If there is a new task in between loads due to scrolling, we got
old tasks from the api that we already loaded.
This happens because:
* tasks are sorted descending by their start time
* we initially request up to 500 from start 0
* we save the amount of tasks there are
* on a new load due to scrolling, we set start to the amount
of tasks knew of -> if there are new tasks now, the start offset
we sent would be too low
To fix this, skip the amount of tasks in the list that were added in the
meantime, which is the new total minus the new total.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ideally we could implement a kind of cursor for our tasks, so that
this scenario would not happen, but I'm not sure if this is feasible
alternatively/additionally we could implement some key constraints
for datastores, or use a Store with a HashMap instead of a vector
(we'd have to do the ordering manually in this case though, which
might be a big overhead for big task lists..)
src/tasks.rs | 44 +++++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/src/tasks.rs b/src/tasks.rs
index 3c531c1..ac8d1c5 100644
--- a/src/tasks.rs
+++ b/src/tasks.rs
@@ -95,7 +95,8 @@ pub enum ViewDialog {
pub enum Msg {
Redraw,
ToggleFilter,
- LoadBatch(u64), // start
+ LoadBatch(u64), // start
+ LoadFinished(Option<u64>, Vec<TaskListItem>), // total
UpdateFilter,
ShowTask,
}
@@ -109,6 +110,7 @@ pub struct ProxmoxTasks {
last_filter: serde_json::Value,
load_timeout: Option<Timeout>,
columns: Rc<Vec<DataTableHeader<TaskListItem>>>,
+ total: Option<u64>,
}
impl ProxmoxTasks {
@@ -192,6 +194,7 @@ impl LoadableComponent for ProxmoxTasks {
start: 0,
load_timeout: None,
columns: Self::columns(ctx),
+ total: None,
}
}
@@ -206,8 +209,6 @@ impl LoadableComponent for ProxmoxTasks {
None => format!("/nodes/{nodename}/tasks"),
};
- let store = self.store.clone();
-
let form_context = self.filter_form_context.read();
let mut filter = form_context.get_submit_data();
@@ -234,13 +235,11 @@ impl LoadableComponent for ProxmoxTasks {
filter["start"] = start.into();
filter["limit"] = BATCH_LIMIT.into();
+ let link = ctx.link().clone();
Box::pin(async move {
- let mut data: Vec<_> = crate::http_get(&path, Some(filter)).await?;
- if start == 0 {
- store.write().set_data(data);
- } else {
- store.write().append(&mut data);
- }
+ let response = crate::http_get_full(&path, Some(filter)).await?;
+ let total = response.attribs.get("total").and_then(|v| v.as_u64());
+ link.send_message(Msg::LoadFinished(total, response.data));
Ok(())
})
}
@@ -279,6 +278,33 @@ impl LoadableComponent for ProxmoxTasks {
}));
false
}
+ Msg::LoadFinished(total, mut data) => {
+ let old_total = self.total.take();
+ self.total = total;
+ if self.start == 0 {
+ self.store.write().set_data(data);
+ } else {
+ // if new elements were added at the front, we need to skip as many from the
+ // newly gathered list, otherwise we have duplicate items
+ match (old_total, self.total) {
+ (Some(old), Some(new)) if new > old => {
+ let to_skip = (new - old) as usize;
+
+ if to_skip <= data.len() {
+ data.drain(..to_skip);
+ }
+ }
+ _ => {}
+ };
+
+ if data.is_empty() {
+ return false;
+ } else {
+ self.store.write().append(&mut data);
+ }
+ }
+ true
+ }
Msg::ShowTask => {
if let Some(on_show_task) = &ctx.props().on_show_task {
let selected_item = self
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next prev parent reply other threads:[~2025-05-07 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 14:37 [yew-devel] [PATCH yew-comp/yew-widget-toolkit 0/4] fix crash and improve task loading Dominik Csapak
2025-05-07 14:37 ` [yew-devel] [PATCH yew-widget-toolkit 1/2] fix #6382: widget: data table: prevent duplicate yew keys for rows Dominik Csapak
2025-05-08 8:50 ` Dietmar Maurer
2025-05-07 14:37 ` [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: data table: add table scroll callback Dominik Csapak
2025-05-08 9:08 ` [yew-devel] applied: " Dietmar Maurer
2025-05-07 14:37 ` [yew-devel] [PATCH yew-comp 1/2] tasks: improve behavior of loading additional tasks Dominik Csapak
2025-05-07 14:38 ` Dominik Csapak [this message]
2025-05-08 9:32 ` [yew-devel] [PATCH yew-comp 2/2] tasks: don't add entries we already loaded Dietmar Maurer
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=20250507143800.3461963-5-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal