Make `exists` return the number of keys that exist

next
Sayan Nandan 4 years ago
parent a5d121c767
commit faaaf79bd8
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

@ -25,7 +25,6 @@
use crate::coredb::CoreDB; use crate::coredb::CoreDB;
use crate::protocol::{responses, ActionGroup, Connection}; use crate::protocol::{responses, ActionGroup, Connection};
use crate::resp::GroupBegin; use crate::resp::GroupBegin;
use libtdb::terrapipe::RespCodes;
use libtdb::TResult; use libtdb::TResult;
/// Run an `EXISTS` query /// Run an `EXISTS` query
@ -34,22 +33,18 @@ pub async fn exists(handle: &CoreDB, con: &mut Connection, act: ActionGroup) ->
if howmany == 0 { if howmany == 0 {
return con.write_response(responses::ACTION_ERR.to_owned()).await; return con.write_response(responses::ACTION_ERR.to_owned()).await;
} }
// Write #<m>\n#<n>\n&<howmany>\n to the stream // Write #<m>\n#<n>\n&1\n to the stream
con.write_response(GroupBegin(howmany)).await?; con.write_response(GroupBegin(1)).await?;
let mut keys = act.into_iter(); let mut how_many_of_them_exist = 0usize;
// HACK(@ohsayan): Figure out what to do here {
while let Some(key) = keys.next() { let rhandle = handle.acquire_read();
let has_key = { act.into_iter().for_each(|key| {
let rhandle = handle.acquire_read(); if rhandle.contains_key(&key) {
rhandle.contains_key(&key) how_many_of_them_exist += 1;
}; }
if has_key { });
con.write_response(RespCodes::Okay).await? drop(rhandle);
} else {
con.write_response(RespCodes::NotFound).await?
}
} }
drop(handle); con.write_response(how_many_of_them_exist).await?;
// We're done here
Ok(()) Ok(())
} }

Loading…
Cancel
Save