partially revert e507c31306

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-11 05:00:29 +00:00
parent 61174dd0d3
commit 3962333043
8 changed files with 13 additions and 18 deletions

View file

@ -82,7 +82,7 @@ pub(crate) async fn get_context_route(
let events_before: Vec<_> = services let events_before: Vec<_> = services
.rooms .rooms
.timeline .timeline
.pdus_rev(Some(sender_user), room_id, Some(base_token.saturating_sub(1))) .pdus_rev(Some(sender_user), room_id, Some(base_token))
.await? .await?
.ready_filter_map(|item| event_filter(item, filter)) .ready_filter_map(|item| event_filter(item, filter))
.filter_map(|item| ignored_filter(&services, item, sender_user)) .filter_map(|item| ignored_filter(&services, item, sender_user))
@ -94,7 +94,7 @@ pub(crate) async fn get_context_route(
let events_after: Vec<_> = services let events_after: Vec<_> = services
.rooms .rooms
.timeline .timeline
.pdus(Some(sender_user), room_id, Some(base_token.saturating_add(1))) .pdus(Some(sender_user), room_id, Some(base_token))
.await? .await?
.ready_filter_map(|item| event_filter(item, filter)) .ready_filter_map(|item| event_filter(item, filter))
.filter_map(|item| ignored_filter(&services, item, sender_user)) .filter_map(|item| ignored_filter(&services, item, sender_user))
@ -169,14 +169,12 @@ pub(crate) async fn get_context_route(
start: events_before start: events_before
.last() .last()
.map(at!(0)) .map(at!(0))
.map(|count| count.saturating_sub(1))
.as_ref() .as_ref()
.map(ToString::to_string), .map(ToString::to_string),
end: events_after end: events_after
.last() .last()
.map(at!(0)) .map(at!(0))
.map(|count| count.saturating_add(1))
.as_ref() .as_ref()
.map(ToString::to_string), .map(ToString::to_string),

View file

@ -138,10 +138,7 @@ pub(crate) async fn get_message_events_route(
let start_token = events.first().map(at!(0)).unwrap_or(from); let start_token = events.first().map(at!(0)).unwrap_or(from);
let next_token = events let next_token = events.last().map(at!(0));
.last()
.map(at!(0))
.map(|count| count.saturating_inc(body.dir));
if !cfg!(feature = "element_hacks") { if !cfg!(feature = "element_hacks") {
if let Some(next_token) = next_token { if let Some(next_token) = next_token {

View file

@ -150,7 +150,6 @@ async fn paginate_relations_with_filter(
Direction::Backward => events.first(), Direction::Backward => events.first(),
} }
.map(at!(0)) .map(at!(0))
.map(|count| count.saturating_inc(dir))
.as_ref() .as_ref()
.map(ToString::to_string); .map(ToString::to_string);

View file

@ -46,7 +46,6 @@ pub(crate) async fn get_threads_route(
.last() .last()
.filter(|_| threads.len() >= limit) .filter(|_| threads.len() >= limit)
.map(at!(0)) .map(at!(0))
.map(|count| count.saturating_sub(1))
.as_ref() .as_ref()
.map(ToString::to_string), .map(ToString::to_string),

View file

@ -55,7 +55,7 @@ pub(crate) async fn get_backfill_route(
pdus: services pdus: services
.rooms .rooms
.timeline .timeline
.pdus_rev(None, &body.room_id, Some(from)) .pdus_rev(None, &body.room_id, Some(from.saturating_add(1)))
.await? .await?
.take(limit) .take(limit)
.filter_map(|(_, pdu)| async move { .filter_map(|(_, pdu)| async move {

View file

@ -57,7 +57,7 @@ impl Data {
) -> impl Stream<Item = PdusIterItem> + Send + '_ { ) -> impl Stream<Item = PdusIterItem> + Send + '_ {
let mut current = ArrayVec::<u8, 16>::new(); let mut current = ArrayVec::<u8, 16>::new();
current.extend(target.to_be_bytes()); current.extend(target.to_be_bytes());
current.extend(from.into_unsigned().to_be_bytes()); current.extend(from.saturating_inc(dir).into_unsigned().to_be_bytes());
let current = current.as_slice(); let current = current.as_slice();
match dir { match dir {
Direction::Forward => self.tofrom_relation.raw_keys_from(current).boxed(), Direction::Forward => self.tofrom_relation.raw_keys_from(current).boxed(),

View file

@ -132,7 +132,7 @@ impl Service {
let current: RawPduId = PduId { let current: RawPduId = PduId {
shortroomid, shortroomid,
shorteventid, shorteventid: shorteventid.saturating_sub(1),
} }
.into(); .into();

View file

@ -13,7 +13,7 @@ use conduit::{
}; };
use database::{Database, Deserialized, Json, KeyVal, Map}; use database::{Database, Deserialized, Json, KeyVal, Map};
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use ruma::{CanonicalJsonObject, EventId, OwnedRoomId, OwnedUserId, RoomId, UserId}; use ruma::{api::Direction, CanonicalJsonObject, EventId, OwnedRoomId, OwnedUserId, RoomId, UserId};
use tokio::sync::Mutex; use tokio::sync::Mutex;
use super::{PduId, RawPduId}; use super::{PduId, RawPduId};
@ -205,7 +205,9 @@ impl Data {
pub(super) async fn pdus_rev<'a>( pub(super) async fn pdus_rev<'a>(
&'a self, user_id: Option<&'a UserId>, room_id: &'a RoomId, until: PduCount, &'a self, user_id: Option<&'a UserId>, room_id: &'a RoomId, until: PduCount,
) -> Result<impl Stream<Item = PdusIterItem> + Send + 'a> { ) -> Result<impl Stream<Item = PdusIterItem> + Send + 'a> {
let current = self.count_to_id(room_id, until).await?; let current = self
.count_to_id(room_id, until, Direction::Backward)
.await?;
let prefix = current.shortroomid(); let prefix = current.shortroomid();
let stream = self let stream = self
.pduid_pdu .pduid_pdu
@ -220,7 +222,7 @@ impl Data {
pub(super) async fn pdus<'a>( pub(super) async fn pdus<'a>(
&'a self, user_id: Option<&'a UserId>, room_id: &'a RoomId, from: PduCount, &'a self, user_id: Option<&'a UserId>, room_id: &'a RoomId, from: PduCount,
) -> Result<impl Stream<Item = PdusIterItem> + Send + 'a> { ) -> Result<impl Stream<Item = PdusIterItem> + Send + 'a> {
let current = self.count_to_id(room_id, from).await?; let current = self.count_to_id(room_id, from, Direction::Forward).await?;
let prefix = current.shortroomid(); let prefix = current.shortroomid();
let stream = self let stream = self
.pduid_pdu .pduid_pdu
@ -267,7 +269,7 @@ impl Data {
} }
} }
async fn count_to_id(&self, room_id: &RoomId, shorteventid: PduCount) -> Result<RawPduId> { async fn count_to_id(&self, room_id: &RoomId, shorteventid: PduCount, dir: Direction) -> Result<RawPduId> {
let shortroomid: ShortRoomId = self let shortroomid: ShortRoomId = self
.services .services
.short .short
@ -278,7 +280,7 @@ impl Data {
// +1 so we don't send the base event // +1 so we don't send the base event
let pdu_id = PduId { let pdu_id = PduId {
shortroomid, shortroomid,
shorteventid, shorteventid: shorteventid.saturating_inc(dir),
}; };
Ok(pdu_id.into()) Ok(pdu_id.into())