simplify and improve db iter State init interface

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-18 22:54:16 +00:00 committed by strawberry
parent 5bce0a3a46
commit 14341bb906
2 changed files with 12 additions and 25 deletions

View file

@ -273,29 +273,6 @@ fn handle_iter(&self, mut cmd: Seek) {
let _chan_sent = chan_result.is_ok();
}
#[implement(Pool)]
#[tracing::instrument(
name = "seek",
level = "trace",
skip_all,
fields(%cmd.map),
)]
fn _handle_seek(&self, mut cmd: Seek) {
let chan = cmd.res.take().expect("missing result channel");
if chan.is_canceled() {
return;
}
match cmd.dir {
| Direction::Forward => cmd.state.seek_fwd(),
| Direction::Reverse => cmd.state.seek_rev(),
};
let chan_result = chan.send(into_send_seek(cmd.state));
let _chan_sent = chan_result.is_ok();
}
#[implement(Pool)]
#[tracing::instrument(
name = "get",

View file

@ -56,20 +56,30 @@ impl<'a> State<'a> {
}
pub(super) fn init_fwd(mut self, from: From<'_>) -> Self {
debug_assert!(self.init, "init must be set to make this call");
debug_assert!(!self.seek, "seek must not be set to make this call");
if let Some(key) = from {
self.inner.seek(key);
self.seek = true;
} else {
self.inner.seek_to_first();
}
self.seek = true;
self
}
pub(super) fn init_rev(mut self, from: From<'_>) -> Self {
debug_assert!(self.init, "init must be set to make this call");
debug_assert!(!self.seek, "seek must not be set to make this call");
if let Some(key) = from {
self.inner.seek_for_prev(key);
self.seek = true;
} else {
self.inner.seek_to_last();
}
self.seek = true;
self
}