Fix relations pagination compliance.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-11-18 22:06:11 +00:00
parent f4eeaaf167
commit 5147b541b5
3 changed files with 105 additions and 80 deletions

View File

@@ -65,12 +65,19 @@ pub fn get_relations<'a>(
&'a self,
shortroomid: ShortRoomId,
target: PduCount,
from: PduCount,
from: Option<PduCount>,
dir: Direction,
user_id: Option<&'a UserId>,
) -> impl Stream<Item = (PduCount, Pdu)> + Send + '_ {
let target = target.to_be_bytes();
let from = from.saturating_inc(dir).to_be_bytes();
let from = from
.map(|from| from.saturating_inc(dir))
.unwrap_or_else(|| match dir {
| Direction::Backward => PduCount::max(),
| Direction::Forward => PduCount::default(),
})
.to_be_bytes();
let mut buf = ArrayVec::<u8, 16>::new();
let start = {
buf.extend(target);
@@ -79,16 +86,16 @@ pub fn get_relations<'a>(
};
match dir {
| Direction::Forward => self
.db
.tofrom_relation
.raw_keys_from(start)
.boxed(),
| Direction::Backward => self
.db
.tofrom_relation
.rev_raw_keys_from(start)
.boxed(),
| Direction::Forward => self
.db
.tofrom_relation
.raw_keys_from(start)
.boxed(),
}
.ignore_err()
.ready_take_while(move |key| key.starts_with(&target))