pinned events(refactor): don't store max_concurrent_requests as a field

since it's used only once
This commit is contained in:
Benjamin Bouvier
2024-08-12 12:19:25 +02:00
committed by Benjamin Bouvier
parent a12a244a89
commit 8f59f45183

View File

@@ -16,17 +16,12 @@ const MAX_CONCURRENT_REQUESTS: usize = 10;
pub struct PinnedEventsLoader {
room: Arc<Box<dyn PinnedEventsRoom>>,
max_events_to_load: usize,
max_concurrent_requests: usize,
}
impl PinnedEventsLoader {
/// Creates a new `PinnedEventsLoader` instance.
pub fn new(room: Box<dyn PinnedEventsRoom>, max_events_to_load: usize) -> Self {
Self {
room: Arc::new(room),
max_events_to_load,
max_concurrent_requests: MAX_CONCURRENT_REQUESTS,
}
Self { room: Arc::new(room), max_events_to_load }
}
/// Loads the pinned events in this room, using the cache first and then
@@ -69,7 +64,7 @@ impl PinnedEventsLoader {
let request_config = Some(
RequestConfig::default()
.retry_limit(3)
.max_concurrent_requests(NonZeroUsize::new(self.max_concurrent_requests)),
.max_concurrent_requests(NonZeroUsize::new(MAX_CONCURRENT_REQUESTS)),
);
let new_events = join_all(event_ids_to_request.into_iter().map(|event_id| {
@@ -184,7 +179,7 @@ impl PinnedEventsRoom for Room {
impl std::fmt::Debug for PinnedEventsLoader {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PinnedEventsLoader")
.field("max_concurrent_requests", &self.max_concurrent_requests)
.field("max_events_to_load", &self.max_events_to_load)
.finish()
}
}