Skip to content

Commit

Permalink
review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Nov 8, 2024
1 parent 5d1c537 commit 5a48f5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 2 additions & 4 deletions relay-server/src/services/projects/cache/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ impl Fetch {

/// Returns when the fetch for the project should be scheduled.
///
/// A return value of `None` indicates, the fetch should be scheduled as soon as possible.
///
/// This can be now (as soon as possible) or a later point in time, if the project is currently
/// in a backoff.
/// This can be now (as soon as possible, indicated by `None`) or a later point in time,
/// if the project is currently in a backoff.
pub fn when(&self) -> Option<Instant> {
self.when
}
Expand Down
16 changes: 13 additions & 3 deletions relay-server/src/utils/squeue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,18 @@ impl<T> Stream for ScheduledQueue<T> {
if let Some(next) = self.inner.peek() {
let when = next.when;

// TODO: maybe optimize here for `when` being in the past,
// currently self goes through one additional wakeup and sleep poll.
// TODO: maybe optimize here for `when` being in the past but the sleep
// is still in the future. This can happen when an item with a shorter
// deadline, than the item at the front of the queue, is inserted.
//
// With the current behaviour we will reset the sleep deadline (in the else branch)
// to a value which will immediately be ready.
// Only after the sleep yields ready, we yield the item.
//
// This is one more wakeup and sleep poll than necessary.
//
// The current design is much simpler and less prone to mistakes since
// the sleep is always synchronized to the first item in the queue.
if matches!(sleep, Poll::Ready(_)) && when <= Instant::now() {
// We already expired the first item, yield it.
let current = self.inner.pop().unwrap();
Expand Down Expand Up @@ -127,7 +137,7 @@ impl<T> PartialOrd for Item<T> {

impl<T> Ord for Item<T> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
other.when.cmp(&self.when)
self.when.cmp(&other.when).reverse()
}
}

Expand Down

0 comments on commit 5a48f5d

Please sign in to comment.