slight cleanup/simplifications to backfil
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1f2e939fd5
commit
f59e8af734
1 changed files with 37 additions and 39 deletions
|
@ -16,7 +16,7 @@ use crate::Ruma;
|
||||||
/// Retrieves events from before the sender joined the room, if the room's
|
/// Retrieves events from before the sender joined the room, if the room's
|
||||||
/// history visibility allows.
|
/// history visibility allows.
|
||||||
pub(crate) async fn get_backfill_route(
|
pub(crate) async fn get_backfill_route(
|
||||||
State(services): State<crate::State>, body: Ruma<get_backfill::v1::Request>,
|
State(services): State<crate::State>, ref body: Ruma<get_backfill::v1::Request>,
|
||||||
) -> Result<get_backfill::v1::Response> {
|
) -> Result<get_backfill::v1::Response> {
|
||||||
AccessCheck {
|
AccessCheck {
|
||||||
services: &services,
|
services: &services,
|
||||||
|
@ -27,7 +27,13 @@ pub(crate) async fn get_backfill_route(
|
||||||
.check()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let until = body
|
let limit = body
|
||||||
|
.limit
|
||||||
|
.min(uint!(100))
|
||||||
|
.try_into()
|
||||||
|
.expect("UInt could not be converted to usize");
|
||||||
|
|
||||||
|
let from = body
|
||||||
.v
|
.v
|
||||||
.iter()
|
.iter()
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -38,32 +44,29 @@ pub(crate) async fn get_backfill_route(
|
||||||
.get_pdu_count(event_id)
|
.get_pdu_count(event_id)
|
||||||
.map(Result::ok)
|
.map(Result::ok)
|
||||||
})
|
})
|
||||||
.ready_fold(PduCount::Backfilled(0), cmp::max)
|
.ready_fold(PduCount::min(), cmp::max)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let limit = body
|
Ok(get_backfill::v1::Response {
|
||||||
.limit
|
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||||
.min(uint!(100))
|
|
||||||
.try_into()
|
|
||||||
.expect("UInt could not be converted to usize");
|
|
||||||
|
|
||||||
let origin = body.origin();
|
origin: services.globals.server_name().to_owned(),
|
||||||
let pdus = services
|
|
||||||
|
pdus: services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.pdus_rev(None, &body.room_id, Some(until))
|
.pdus_rev(None, &body.room_id, Some(from))
|
||||||
.await?
|
.await?
|
||||||
.take(limit)
|
.take(limit)
|
||||||
.filter_map(|(_, pdu)| async move {
|
.filter_map(|(_, pdu)| async move {
|
||||||
if !services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.server_can_see_event(origin, &pdu.room_id, &pdu.event_id)
|
.server_can_see_event(body.origin(), &pdu.room_id, &pdu.event_id)
|
||||||
.await
|
.await
|
||||||
{
|
.then_some(pdu)
|
||||||
return None;
|
})
|
||||||
}
|
.filter_map(|pdu| async move {
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
|
@ -73,11 +76,6 @@ pub(crate) async fn get_backfill_route(
|
||||||
})
|
})
|
||||||
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
|
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await,
|
||||||
|
|
||||||
Ok(get_backfill::v1::Response {
|
|
||||||
origin: services.globals.server_name().to_owned(),
|
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
|
||||||
pdus,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue