From 35567583869c2c24a2e040a0f1e755d4e3d17880 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 9 Apr 2024 10:49:52 +0100 Subject: [PATCH] cli: fix rad inbox clear output If multiple ids are specified for `rad inbox clear`, it would report that only 1 item was cleared, when in fact multiple were. This was found to be due to the SQL code returning a change count of `1`. This is likely due to the way the statement is being reset each time. The `sqlite` library does not seem to easily support the usage of `IN` in a `WHERE` clause. So instead, the `count` is aggregated in the loop and returned instead. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-cli/examples/rad-inbox.md | 2 +- radicle/src/node/notifications/store.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/radicle-cli/examples/rad-inbox.md b/radicle-cli/examples/rad-inbox.md index bdcdb807..13a714a8 100644 --- a/radicle-cli/examples/rad-inbox.md +++ b/radicle-cli/examples/rad-inbox.md @@ -85,7 +85,7 @@ $ rad inbox show 1 ``` ``` ~alice -$ rad inbox clear +$ rad inbox clear 1 2 ✓ Cleared 2 item(s) from your inbox $ rad inbox Your inbox is empty. diff --git a/radicle/src/node/notifications/store.rs b/radicle/src/node/notifications/store.rs index eb6f240f..ac7c3750 100644 --- a/radicle/src/node/notifications/store.rs +++ b/radicle/src/node/notifications/store.rs @@ -196,12 +196,16 @@ impl Store { .db .prepare("DELETE FROM `repository-notifications` WHERE rowid = ?")?; + // N.b. we need to keep the count manually since the change count + // will always be `1` because of each reset. + let mut count = 0; for id in ids { stmt.bind((1, *id as i64))?; stmt.next()?; stmt.reset()?; + count += self.db.change_count(); } - Ok(self.db.change_count()) + Ok(count) }) }