Skip to content

Commit d97329c

Browse files
committed
fix: add Aggregate type
1 parent a81617d commit d97329c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

primitives/src/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{AdUnit, EventSubmission, TargetingTag, ValidatorDesc, ValidatorId};
1111
use hex::{FromHex, FromHexError};
1212
use std::ops::Deref;
1313

14-
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Copy, Clone)]
14+
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Copy, Clone, Hash)]
1515
#[serde(transparent)]
1616
pub struct ChannelId(#[serde(with = "SerHex::<StrictPfx>")] [u8; 32]);
1717

sentry/src/event_aggregator.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ use std::sync::Arc;
1616
use std::time::Duration;
1717
use tokio::time::delay_for;
1818

19+
pub(crate) type Aggregate = Arc<RwLock<HashMap<ChannelId, EventAggregate>>>;
20+
1921
#[derive(Default, Clone)]
2022
pub struct EventAggregator {
21-
aggregate: Arc<RwLock<HashMap<String, EventAggregate>>>,
23+
aggregate: Aggregate,
2224
}
2325

2426
pub fn new_aggr(channel_id: &ChannelId) -> EventAggregate {
@@ -33,16 +35,16 @@ async fn store(
3335
db: &DbPool,
3436
channel_id: &ChannelId,
3537
logger: &Logger,
36-
aggr: Arc<RwLock<HashMap<String, EventAggregate>>>,
38+
aggr: Aggregate,
3739
) {
3840
let mut recorder = aggr.write().await;
39-
let ev_aggr: Option<&EventAggregate> = recorder.get(&channel_id.to_string());
41+
let ev_aggr: Option<&EventAggregate> = recorder.get(channel_id);
4042
if let Some(data) = ev_aggr {
4143
if let Err(e) = insert_event_aggregate(&db, &channel_id, data).await {
4244
error!(&logger, "{}", e; "eventaggregator" => "store");
4345
} else {
4446
// reset aggr
45-
recorder.insert(channel_id.to_string(), new_aggr(&channel_id));
47+
recorder.insert(channel_id.to_owned(), new_aggr(&channel_id));
4648
};
4749
}
4850
}
@@ -75,11 +77,11 @@ impl EventAggregator {
7577
let channel_id = channel.id;
7678
let logger = app.logger.clone();
7779

78-
let mut aggr: &mut EventAggregate = match recorder.get_mut(&channel.id.to_string()) {
80+
let mut aggr: &mut EventAggregate = match recorder.get_mut(&channel.id) {
7981
Some(aggr) => aggr,
8082
None => {
8183
// insert into
82-
recorder.insert(channel.id.to_string(), new_aggr(&channel.id));
84+
recorder.insert(channel.id, new_aggr(&channel.id));
8385

8486
// spawn async task that persists
8587
// the channel events to database
@@ -102,7 +104,7 @@ impl EventAggregator {
102104
}
103105

104106
recorder
105-
.get_mut(&channel.id.to_string())
107+
.get_mut(&channel.id)
106108
.expect("should have aggr, we just inserted")
107109
}
108110
};

0 commit comments

Comments
 (0)