From 6bcfc5c1a4f2c45b946ff252b9b5aa489bf77253 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 28 Sep 2020 15:32:10 +0200 Subject: [PATCH] api2/status: use the TaskListInfoIterator here this means that limiting with epoch now works correctly also change the api type to i64, since that is what the starttime is saved as Signed-off-by: Dominik Csapak --- src/api2/status.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/api2/status.rs b/src/api2/status.rs index eb8c43cd..fd40f14d 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -182,7 +182,7 @@ fn datastore_status( input: { properties: { since: { - type: u64, + type: i64, description: "Only list tasks since this UNIX epoch.", optional: true, }, @@ -200,6 +200,7 @@ fn datastore_status( )] /// List tasks. pub fn list_tasks( + since: Option, _param: Value, rpcenv: &mut dyn RpcEnvironment, ) -> Result, Error> { @@ -209,13 +210,28 @@ pub fn list_tasks( let user_privs = user_info.lookup_privs(&userid, &["system", "tasks"]); let list_all = (user_privs & PRIV_SYS_AUDIT) != 0; + let since = since.unwrap_or_else(|| 0); - // TODO: replace with call that gets all task since 'since' epoch - let list: Vec = server::read_task_list()? - .into_iter() - .map(TaskListItem::from) - .filter(|entry| list_all || entry.user == userid) - .collect(); + let list: Vec = server::TaskListInfoIterator::new(false)? + .take_while(|info| { + match info { + Ok(info) => info.upid.starttime > since, + Err(_) => false + } + }) + .filter_map(|info| { + match info { + Ok(info) => { + if list_all || info.upid.userid == userid { + Some(Ok(TaskListItem::from(info))) + } else { + None + } + } + Err(err) => Some(Err(err)) + } + }) + .collect::, Error>>()?; Ok(list.into()) }