Skip to content

Commit bcac670

Browse files
committed
review comments
1 parent 46c14b5 commit bcac670

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

relay-server/src/actors/project_cache.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,20 @@ impl Queue {
413413
pub fn dequeue<P>(
414414
&mut self,
415415
partial_key: &ProjectKey,
416-
f: P,
416+
predicate: P,
417417
) -> Vec<(Box<Envelope>, EnvelopeContext)>
418418
where
419419
P: Fn(&QueueKey) -> bool,
420420
{
421421
let mut result = Vec::new();
422422

423-
let mut keys = self.index.remove(partial_key).unwrap_or_default();
423+
let mut queue_keys = self.index.remove(partial_key).unwrap_or_default();
424424
let mut index = BTreeSet::new();
425425

426-
while let Some(queue_key) = keys.pop_first() {
426+
while let Some(queue_key) = queue_keys.pop_first() {
427427
// Find those keys which match predicates and return keys into the index, where
428428
// predicate is failing.
429-
if f(&queue_key) {
429+
if predicate(&queue_key) {
430430
if let Some(envelopes) = self.buffer.remove(&queue_key) {
431431
result.extend(envelopes);
432432
}
@@ -541,24 +541,18 @@ impl ProjectCacheBroker {
541541
}
542542

543543
let envelopes = self.pending_envelopes.dequeue(&project_key, |queue_key| {
544-
// Pick envelopes which belong to the incoming project.
545-
for key in &[queue_key.root_key, queue_key.sampling_key] {
546-
if project_key == *key {
547-
continue;
548-
}
544+
let partial_key = if queue_key.root_key == project_key {
545+
queue_key.sampling_key
546+
} else {
547+
queue_key.root_key
548+
};
549549

550-
// We return false if project is not cached or its state is invalid.
551-
if self
552-
.projects
553-
.get(&queue_key.sampling_key)
554-
// Make sure we have only cached and valid state.
555-
.and_then(|p| p.valid_state())
556-
.map_or(true, |s| s.invalid())
557-
{
558-
return false;
559-
}
560-
}
561-
true
550+
// We return false if project is not cached or its state is invalid, true otherwise.
551+
self.projects
552+
.get(&partial_key)
553+
// Make sure we have only cached and valid state.
554+
.and_then(|p| p.valid_state())
555+
.map_or(false, |s| !s.invalid())
562556
});
563557

564558
// Flush envelopes where both states have resolved.

0 commit comments

Comments
 (0)