-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref(spooler): Remove use of legacy project cache #4419
Draft
iambriccardo
wants to merge
8
commits into
master
Choose a base branch
from
riccardo/ref/remove-project-check
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+381
−451
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d09fe4
ref(spooler): Remove use of legacy project cache
iambriccardo f560eb9
Fix
iambriccardo 04c0631
Fix
iambriccardo e81db18
Fix
iambriccardo 926cd7b
Fix
iambriccardo 98fcf28
Fix
iambriccardo 1b070eb
Fix
iambriccardo b2b4e1a
Fix
iambriccardo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,31 +3,154 @@ use relay_base_schema::project::ProjectKey; | |
use crate::Envelope; | ||
|
||
/// Struct that represents two project keys. | ||
#[derive(Debug, Clone, Copy, Eq, Hash, Ord, PartialOrd, PartialEq)] | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct ProjectKeyPair { | ||
pub own_key: ProjectKey, | ||
pub sampling_key: ProjectKey, | ||
own_key: ProjectKey, | ||
sampling_key: Option<ProjectKey>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided that I would prefer to encode in the pair the lack of sampling key and rather expose different methods for making it behave like previously, where they were both set and the fallback of |
||
} | ||
|
||
impl ProjectKeyPair { | ||
pub fn new(own_key: ProjectKey, sampling_key: ProjectKey) -> Self { | ||
Self { | ||
own_key, | ||
sampling_key, | ||
sampling_key: Some(sampling_key), | ||
} | ||
} | ||
|
||
pub fn own_key(&self) -> ProjectKey { | ||
self.own_key | ||
} | ||
|
||
pub fn sampling_key(&self) -> Option<ProjectKey> { | ||
self.sampling_key | ||
} | ||
|
||
pub fn sampling_key_unwrap(&self) -> ProjectKey { | ||
self.sampling_key.unwrap_or(self.own_key) | ||
} | ||
|
||
pub fn from_envelope(envelope: &Envelope) -> Self { | ||
let own_key = envelope.meta().public_key(); | ||
let sampling_key = envelope.sampling_key().unwrap_or(own_key); | ||
Self::new(own_key, sampling_key) | ||
let sampling_key = envelope.sampling_key(); | ||
Self { | ||
own_key, | ||
sampling_key, | ||
} | ||
} | ||
|
||
pub fn iter(&self) -> impl Iterator<Item = ProjectKey> { | ||
let Self { | ||
own_key, | ||
sampling_key, | ||
} = self; | ||
std::iter::once(*own_key).chain((own_key != sampling_key).then_some(*sampling_key)) | ||
std::iter::once(*own_key).chain(sampling_key.filter(|k| k != own_key)) | ||
} | ||
} | ||
|
||
impl PartialEq for ProjectKeyPair { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.own_key() == other.own_key() | ||
&& self.sampling_key_unwrap() == other.sampling_key_unwrap() | ||
} | ||
} | ||
|
||
impl Eq for ProjectKeyPair {} | ||
|
||
impl PartialOrd for ProjectKeyPair { | ||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
impl Ord for ProjectKeyPair { | ||
fn cmp(&self, other: &Self) -> std::cmp::Ordering { | ||
let own_comparison = self.own_key().cmp(&other.own_key()); | ||
if own_comparison != std::cmp::Ordering::Equal { | ||
return own_comparison; | ||
}; | ||
self.sampling_key_unwrap().cmp(&other.sampling_key_unwrap()) | ||
} | ||
} | ||
|
||
impl std::hash::Hash for ProjectKeyPair { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.own_key().hash(state); | ||
self.sampling_key_unwrap().hash(state); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::collections::HashSet; | ||
|
||
#[test] | ||
fn test_project_key_pair_new() { | ||
let own = ProjectKey::parse("a94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
let sampling = ProjectKey::parse("b94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
|
||
let pair = ProjectKeyPair::new(own, sampling); | ||
assert_eq!(pair.own_key(), own); | ||
assert_eq!(pair.sampling_key_unwrap(), sampling); | ||
} | ||
|
||
#[test] | ||
fn test_project_key_pair_equality() { | ||
let key1 = ProjectKey::parse("a94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
let key2 = ProjectKey::parse("b94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
|
||
let pair1 = ProjectKeyPair::new(key1, key2); | ||
let pair2 = ProjectKeyPair::new(key1, key2); | ||
let pair3 = ProjectKeyPair::new(key2, key1); | ||
|
||
assert_eq!(pair1, pair2); | ||
assert_ne!(pair1, pair3); | ||
} | ||
|
||
#[test] | ||
fn test_project_key_pair_ordering() { | ||
let key1 = ProjectKey::parse("a94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
let key2 = ProjectKey::parse("b94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
|
||
let pair1 = ProjectKeyPair::new(key1, key2); | ||
let pair2 = ProjectKeyPair::new(key2, key1); | ||
let pair3 = ProjectKeyPair { | ||
own_key: key1, | ||
sampling_key: None, | ||
}; | ||
|
||
assert!(pair1 < pair2); | ||
assert!(pair3 < pair2); | ||
} | ||
|
||
#[test] | ||
fn test_project_key_pair_hash() { | ||
let key1 = ProjectKey::parse("a94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
let key2 = ProjectKey::parse("b94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
|
||
let pair1 = ProjectKeyPair::new(key1, key2); | ||
let pair2 = ProjectKeyPair::new(key1, key2); | ||
let pair3 = ProjectKeyPair::new(key2, key1); | ||
|
||
let mut set = HashSet::new(); | ||
set.insert(pair1); | ||
assert!(set.contains(&pair2)); | ||
assert!(!set.contains(&pair3)); | ||
} | ||
|
||
#[test] | ||
fn test_project_key_pair_iter() { | ||
let key1 = ProjectKey::parse("a94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
let key2 = ProjectKey::parse("b94ae32be2584e0bbd7a4cbb95971fee").unwrap(); | ||
|
||
// Test with different sampling key | ||
let pair = ProjectKeyPair::new(key1, key2); | ||
let keys: Vec<_> = pair.iter().collect(); | ||
assert_eq!(keys, vec![key1, key2]); | ||
|
||
// Test with same key (should only yield one key) | ||
let pair = ProjectKeyPair::new(key1, key1); | ||
let keys: Vec<_> = pair.iter().collect(); | ||
assert_eq!(keys, vec![key1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided that I would prefer to encode in the pair the lack of sampling key and rather expose different methods for making it behave like previously, where they were both set and the fallback of
sampling_key
wasown_key
.