Skip to content

Commit 83c16f1

Browse files
committed
update: insert event aggregate total
1 parent d175733 commit 83c16f1

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

sentry/src/db/event_aggregate.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use crate::db::DbPool;
22
use bb8::RunError;
33
// use bb8_postgres::tokio_postgres::types::{ToSql, FromSql};
44
use chrono::{DateTime, Utc};
5+
use postgres_types::{FromSql, ToSql};
56
use primitives::sentry::EventAggregate;
6-
use primitives::{ChannelId, ValidatorId};
77
use primitives::BigNum;
8+
use primitives::{ChannelId, ValidatorId};
89
use std::ops::Add;
9-
use postgres_types::{ToSql, FromSql};
1010

1111
pub async fn list_event_aggregates(
1212
pool: &DbPool,
@@ -65,7 +65,6 @@ struct EventData {
6565
event_payout: String,
6666
}
6767

68-
6968
pub async fn insert_event_aggregate(
7069
pool: &DbPool,
7170
channel_id: &ChannelId,
@@ -83,18 +82,15 @@ pub async fn insert_event_aggregate(
8382
let mut total_event_payouts: BigNum = 0.into();
8483
for (earner, event_count) in event_counts {
8584
let event_payout = aggr.event_payouts[earner].clone();
86-
data.extend(vec![
87-
EventData {
88-
id: id.clone(),
89-
event_type: event_type.clone(),
90-
earner: Some(earner.clone()),
91-
event_count: event_count.to_string(),
92-
event_payout: event_payout.to_string(),
93-
}
94-
95-
]);
96-
97-
// total sum
85+
data.extend(vec![EventData {
86+
id: id.clone(),
87+
event_type: event_type.clone(),
88+
earner: Some(earner.clone()),
89+
event_count: event_count.to_string(),
90+
event_payout: event_payout.to_string(),
91+
}]);
92+
93+
// total sum
9894
total_event_counts = event_count.add(&total_event_counts);
9995
total_event_payouts = total_event_payouts.add(event_payout);
10096

@@ -117,15 +113,13 @@ pub async fn insert_event_aggregate(
117113
index += 5;
118114
}
119115
// extend with
120-
data.extend(vec![
121-
EventData {
122-
id: id.clone(),
123-
event_type: event_type.clone(),
124-
earner: None,
125-
event_count: total_event_counts.to_string(),
126-
event_payout: total_event_payouts.to_string(),
127-
}
128-
]);
116+
data.extend(vec![EventData {
117+
id: id.clone(),
118+
event_type: event_type.clone(),
119+
earner: None,
120+
event_count: total_event_counts.to_string(),
121+
event_payout: total_event_payouts.to_string(),
122+
}]);
129123

130124
values.push(format!(
131125
"(${}, ${}, ${}, ${}, ${})",
@@ -136,8 +130,6 @@ pub async fn insert_event_aggregate(
136130
index + 5
137131
));
138132
index += 5;
139-
140-
141133
}
142134
}
143135

0 commit comments

Comments
 (0)