diff --git a/relay-server/src/services/buffer/envelope_stack/sqlite.rs b/relay-server/src/services/buffer/envelope_stack/sqlite.rs index 44edc80b12..13e1fb5a13 100644 --- a/relay-server/src/services/buffer/envelope_stack/sqlite.rs +++ b/relay-server/src/services/buffer/envelope_stack/sqlite.rs @@ -120,7 +120,7 @@ impl SqliteEnvelopeStack { /// In case an envelope fails deserialization due to malformed data in the database, the affected /// envelope will not be unspooled and unspooling will continue with the remaining envelopes. async fn unspool_from_disk(&mut self) -> Result<(), SqliteEnvelopeStackError> { - let mut envelopes = relay_statsd::metric!(timer(RelayTimers::BufferUnspool), { + let envelopes = relay_statsd::metric!(timer(RelayTimers::BufferUnspool), { self.envelope_store .delete_many( self.own_key, @@ -139,11 +139,6 @@ impl SqliteEnvelopeStack { return Ok(()); } - // Since the store returns the envelopes sorted in descending order, we want to put them - // in reverse into the vector in the buffer, because we want to pop the last element always, - // which has to be the newest (aka with the biggest timestamp). - envelopes.reverse(); - // We push in the back of the buffer, since we still want to give priority to // incoming envelopes that have a more recent timestamp. self.batches_buffer_size += envelopes.len(); diff --git a/relay-server/src/services/buffer/envelope_store/sqlite.rs b/relay-server/src/services/buffer/envelope_store/sqlite.rs index aa39502330..06ab3b80c3 100644 --- a/relay-server/src/services/buffer/envelope_store/sqlite.rs +++ b/relay-server/src/services/buffer/envelope_store/sqlite.rs @@ -1,4 +1,3 @@ -use std::cmp::Reverse; use std::error::Error; use std::path::Path; use std::pin::pin; @@ -371,12 +370,12 @@ impl SqliteEnvelopeStore { } } - // We sort envelopes by `received_at`. + // We sort envelopes by `received_at` in ascending order. // // Unfortunately we have to do this because SQLite `DELETE` with `RETURNING` doesn't // return deleted rows in a specific order. extracted_envelopes.sort_by_key(|a| { - Reverse(UnixTimestamp::from_datetime(a.received_at()).unwrap_or(UnixTimestamp::now())) + UnixTimestamp::from_datetime(a.received_at()).unwrap_or(UnixTimestamp::now()) }); Ok(extracted_envelopes) @@ -553,10 +552,7 @@ mod tests { .unwrap(); assert_eq!(extracted_envelopes.len(), 5); for (i, extracted_envelope) in extracted_envelopes.iter().enumerate().take(5) { - assert_eq!( - extracted_envelope.event_id(), - envelopes[5..][4 - i].event_id() - ); + assert_eq!(extracted_envelope.event_id(), envelopes[5..][i].event_id()); } // We check that if we load more than the envelopes stored on disk, we still get back at @@ -567,10 +563,7 @@ mod tests { .unwrap(); assert_eq!(extracted_envelopes.len(), 5); for (i, extracted_envelope) in extracted_envelopes.iter().enumerate().take(5) { - assert_eq!( - extracted_envelope.event_id(), - envelopes[0..5][4 - i].event_id() - ); + assert_eq!(extracted_envelope.event_id(), envelopes[0..5][i].event_id()); } }