Skip to content

Commit 663decc

Browse files
authored
Merge pull request #1 from AdExNetwork/improvements-analytics-recorder
Improvements on the code
2 parents 502d6ab + 19187a5 commit 663decc

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

sentry/src/analytics_recorder.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ use slog::{error, Logger};
1010
pub fn get_payout(channel: &Channel, event: &Event) -> BigNum {
1111
match event {
1212
Event::Impression { .. } => channel.spec.min_per_impression.clone(),
13-
Event::Click { .. } => {
14-
if let Some(pricing) = channel.spec.pricing_bounds.clone() {
15-
if let Some(click) = pricing.click {
16-
return click.min;
17-
}
18-
}
19-
20-
Default::default()
21-
}
13+
Event::Click { .. } => channel
14+
.spec
15+
.pricing_bounds
16+
.as_ref()
17+
.and_then(|pricing_bound| pricing_bound.click.as_ref())
18+
.map(|click| click.min.clone())
19+
.unwrap_or_default(),
2220
_ => Default::default(),
2321
}
2422
}
@@ -84,7 +82,7 @@ pub async fn record(
8482
.ignore();
8583
}
8684

87-
if let Some(country) = session.country.clone() {
85+
if let Some(country) = &session.country {
8886
db.zincr(
8987
format!(
9088
"{}:{}:{}:{}",
@@ -129,6 +127,6 @@ pub async fn record(
129127
});
130128

131129
if let Err(err) = db.query_async::<_, Option<String>>(&mut conn).await {
132-
error!(&logger, "Server error: {}", err; "module" => "analytics-recorder");
130+
error!(&logger, "Redis Database error: {}", err; "module" => "analytics-recorder");
133131
}
134132
}

sentry/src/db/event_aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn latest_new_state(
5555
pub async fn latest_heartbeats(
5656
pool: &DbPool,
5757
channel_id: &ChannelId,
58-
validator_id: ValidatorId,
58+
validator_id: &ValidatorId,
5959
) -> Result<Vec<HeartbeatValidatorMessage>, RunError<bb8_postgres::tokio_postgres::Error>> {
6060
pool
6161
.run(move |connection| {

sentry/src/event_aggregator.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ impl EventAggregator {
140140
.for_each(|ev| event_reducer::reduce(&record.channel, &mut record.aggregate, ev));
141141

142142
if ANALYTICS_RECORDER.is_some() {
143-
let logger = app.logger.clone();
144143
tokio::spawn(analytics_recorder::record(
145144
redis.clone(),
146145
record.channel.clone(),
147146
session.clone(),
148147
events.to_owned().to_vec(),
149-
logger,
148+
app.logger.clone(),
150149
));
151150
}
152151

@@ -155,13 +154,7 @@ impl EventAggregator {
155154
drop(channel_recorder);
156155

157156
if aggr_throttle == 0 {
158-
store(
159-
&app.pool,
160-
&channel_id,
161-
&app.logger.clone(),
162-
recorder.clone(),
163-
)
164-
.await;
157+
store(&app.pool, &channel_id, &app.logger, recorder.clone()).await;
165158
}
166159

167160
Ok(())

sentry/src/routes/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ pub async fn last_approved<A: Adapter>(
138138
let heartbeats = if query.with_heartbeat.is_some() {
139139
let result = try_join_all(
140140
validators
141-
.into_iter()
142-
.map(|validator| latest_heartbeats(&app.pool, &channel_id, validator.id.clone())),
141+
.iter()
142+
.map(|validator| latest_heartbeats(&app.pool, &channel_id, &validator.id)),
143143
)
144144
.await?;
145145
Some(result.into_iter().flatten().collect::<Vec<_>>())

0 commit comments

Comments
 (0)