Skip to content

Commit

Permalink
implemented quiet pdel
Browse files Browse the repository at this point in the history
  • Loading branch information
babymotte committed Aug 9, 2024
1 parent ff3b474 commit 7df30cd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion worterbuch-cli/src/bin/wbpdel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct Args {
/// Set a client name on the server
#[arg(short, long)]
name: Option<String>,
/// Don't return deleted values
#[arg(short, long)]
quiet: bool,
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
Expand Down Expand Up @@ -125,7 +128,7 @@ async fn run(subsys: SubsystemHandle) -> Result<()> {
}
},
recv = next_item(&mut rx, done) => match recv {
Some(key ) => trans_id = wb.pdelete_async(key).await?,
Some(key ) => trans_id = wb.pdelete_async(key, args.quiet).await?,
None => done = true,
},
}
Expand Down
20 changes: 12 additions & 8 deletions worterbuch-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ pub(crate) enum Command {
PGetAsync(Key, oneshot::Sender<TransactionId>),
Delete(Key, oneshot::Sender<(Option<Value>, TransactionId)>),
DeleteAsync(Key, oneshot::Sender<TransactionId>),
PDelete(Key, oneshot::Sender<(KeyValuePairs, TransactionId)>),
PDeleteAsync(Key, oneshot::Sender<TransactionId>),
PDelete(Key, bool, oneshot::Sender<(KeyValuePairs, TransactionId)>),
PDeleteAsync(Key, bool, oneshot::Sender<TransactionId>),
Ls(
Option<Key>,
oneshot::Sender<(Vec<RegularKeySegment>, TransactionId)>,
Expand Down Expand Up @@ -343,9 +343,9 @@ impl Worterbuch {
})
}

pub async fn pdelete_async(&self, key: Key) -> ConnectionResult<TransactionId> {
pub async fn pdelete_async(&self, key: Key, quiet: bool) -> ConnectionResult<TransactionId> {
let (tx, rx) = oneshot::channel();
let cmd = Command::PDeleteAsync(key, tx);
let cmd = Command::PDeleteAsync(key, quiet, tx);
log::debug!("Queuing command {cmd:?}");
self.commands.send(cmd).await?;
log::debug!("Command queued.");
Expand All @@ -356,9 +356,10 @@ impl Worterbuch {
pub async fn pdelete_generic(
&self,
key: Key,
quiet: bool,
) -> ConnectionResult<(KeyValuePairs, TransactionId)> {
let (tx, rx) = oneshot::channel();
let cmd = Command::PDelete(key, tx);
let cmd = Command::PDelete(key, quiet, tx);
log::debug!("Queuing command {cmd:?}");
self.commands.send(cmd).await?;
log::debug!("Command queued.");
Expand All @@ -369,8 +370,9 @@ impl Worterbuch {
pub async fn pdelete<T: DeserializeOwned>(
&self,
key: Key,
quiet: bool,
) -> ConnectionResult<(TypedKeyValuePairs<T>, TransactionId)> {
let (kvps, tid) = self.pdelete_generic(key).await?;
let (kvps, tid) = self.pdelete_generic(key, quiet).await?;
let typed_kvps = deserialize_key_value_pairs(kvps)?;
Ok((typed_kvps, tid))
}
Expand Down Expand Up @@ -1276,18 +1278,20 @@ async fn process_incoming_command(
key,
}))
}
Command::PDelete(request_pattern, callback) => {
Command::PDelete(request_pattern, quiet, callback) => {
callbacks.pdel.insert(transaction_id, callback);
Some(CM::PDelete(PDelete {
transaction_id,
request_pattern,
quiet: Some(quiet),
}))
}
Command::PDeleteAsync(request_pattern, callback) => {
Command::PDeleteAsync(request_pattern, quiet, callback) => {
callback.send(transaction_id).expect("error in callback");
Some(CM::PDelete(PDelete {
transaction_id,
request_pattern,
quiet: Some(quiet),
}))
}
Command::Ls(parent, callback) => {
Expand Down
3 changes: 3 additions & 0 deletions worterbuch-common/schema/client.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ properties:
requestPattern:
description: The deletion pattern
type: string
quiet:
description: If true, the server will not send the deleted values back to the client
type: boolean
additionalProperties: false
required:
- transactionId
Expand Down
1 change: 1 addition & 0 deletions worterbuch-common/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub struct Delete {
pub struct PDelete {
pub transaction_id: TransactionId,
pub request_pattern: RequestPattern,
pub quiet: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
6 changes: 5 additions & 1 deletion worterbuch/src/server/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,11 @@ async fn pdelete(
let response = PState {
transaction_id: msg.transaction_id,
request_pattern: msg.request_pattern,
event: PStateEvent::Deleted(deleted),
event: PStateEvent::Deleted(if msg.quiet.unwrap_or(false) {
vec![]
} else {
deleted
}),
};

client
Expand Down

0 comments on commit 7df30cd

Please sign in to comment.