Skip to content

Commit 7121cb0

Browse files
committed
remove: redundant as_slice() calls
1 parent 513b5a1 commit 7121cb0

File tree

8 files changed

+28
-29
lines changed

8 files changed

+28
-29
lines changed

primitives/src/big_num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,4 @@ mod test {
283283
let expected: BigNum = 11.into();
284284
assert_eq!(expected, &big_num * &ratio);
285285
}
286-
}
286+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-- This file should undo anything in `up.sql`
2-
DROP TABLE event_aggregates, validator_messages, channels;
2+
DROP AGGREGATE jsonb_object_agg(jsonb);
3+
DROP TABLE event_aggregates, validator_messages, channels;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
DELETE FROM event_aggregates;
2+
DELETE FROM validator_messages;
13
DELETE FROM channels;

sentry/migrations/20190806011140_initial-tables/up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ CREATE TABLE event_aggregates
3131
created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
3232
event_type VARCHAR(255) NOT NULL,
3333
earner VARCHAR(255),
34-
event_counts VARCHAR NOT NULL,
35-
event_payouts VARCHAR NOT NULL
34+
count BIGINT NOT NULL,
35+
payout BIGINT NOT NULL
3636
);
3737

3838
CREATE INDEX idx_event_aggregates_created ON event_aggregates (created);

sentry/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub async fn setup_migrations(environment: &str) {
9191

9292
// Define Migrations
9393
config
94-
.use_migrations(&migrations.as_slice())
94+
.use_migrations(&migrations)
9595
.expect("Loading migrations failed");
9696

9797
// Reload config, ping the database for applied migrations

sentry/src/db/event_aggregate.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::db::DbPool;
22
use bb8::RunError;
33
use bb8_postgres::tokio_postgres::binary_copy::BinaryCopyInWriter;
4-
use bb8_postgres::tokio_postgres::types::{Type, ToSql};
4+
use bb8_postgres::tokio_postgres::types::{ToSql, Type};
55
use bb8_postgres::tokio_postgres::Error;
66
use chrono::{DateTime, Utc};
77
use futures::pin_mut;
@@ -52,13 +52,13 @@ pub async fn list_event_aggregates(
5252
'eventCounts',
5353
jsonb_object_agg(
5454
jsonb_build_object(
55-
earner, event_counts
55+
earner, count::text
5656
)
5757
),
5858
'eventPayouts',
5959
jsonb_object_agg(
6060
jsonb_build_object(
61-
earner, event_payouts
61+
earner, payout::text
6262
)
6363
)
6464
)
@@ -92,8 +92,8 @@ struct EventData {
9292
id: String,
9393
event_type: String,
9494
earner: Option<String>,
95-
event_count: String,
96-
event_payout: String,
95+
event_count: BigNum,
96+
event_payout: BigNum,
9797
created: DateTime<Utc>,
9898
}
9999

@@ -113,44 +113,45 @@ pub async fn insert_event_aggregate(
113113
let mut total_event_payouts: BigNum = 0.into();
114114
for (earner, event_count) in event_counts {
115115
let event_payout = aggr.event_payouts[earner].clone();
116-
data.extend(vec![EventData {
116+
117+
data.push(EventData {
117118
id: id.clone(),
118119
event_type: event_type.clone(),
119120
earner: Some(earner.to_string()),
120-
event_count: event_count.to_string(),
121-
event_payout: event_payout.to_string(),
121+
event_count: event_count.to_owned(),
122+
event_payout: event_payout.clone(),
122123
created,
123-
}]);
124+
});
124125

125126
// total sum
126127
total_event_counts = event_count.add(&total_event_counts);
127-
total_event_payouts = total_event_payouts.add(event_payout);
128+
total_event_payouts = event_payout.add(total_event_payouts);
128129
}
129130

130-
data.extend(vec![EventData {
131+
data.push(EventData {
131132
id: id.clone(),
132133
event_type: event_type.clone(),
133134
earner: None,
134-
event_count: total_event_counts.to_string(),
135-
event_payout: total_event_payouts.to_string(),
135+
event_count: total_event_counts,
136+
event_payout: total_event_payouts,
136137
created,
137-
}]);
138+
});
138139
}
139140
}
140141

141142
let result = pool
142143
.run(move |connection| {
143144
async move {
144145
let mut err: Option<Error> = None;
145-
let sink = match connection.copy_in("COPY event_aggregates(channel_id, created, event_type, event_counts, event_payouts, earner) FROM STDIN BINARY").await {
146+
let sink = match connection.copy_in("COPY event_aggregates(channel_id, created, event_type, count, payout, earner) FROM STDIN BINARY").await {
146147
Ok(sink) => sink,
147148
Err(e) => return Err((e, connection))
148149
};
149150

150-
let writer = BinaryCopyInWriter::new(sink, &[Type::VARCHAR, Type::TIMESTAMPTZ, Type::VARCHAR, Type::VARCHAR, Type::VARCHAR, Type::VARCHAR]);
151+
let writer = BinaryCopyInWriter::new(sink, &[Type::VARCHAR, Type::TIMESTAMPTZ, Type::VARCHAR, Type::INT8, Type::INT8, Type::VARCHAR]);
151152
pin_mut!(writer);
152153
for item in data {
153-
if let Err(e) = writer.as_mut().write(&[&item.id, &item.created, &item.event_type, &item.event_count, &item.event_payout, &item.earner]).await {
154+
if let Err(e) = writer.as_mut().write(&[&item.id, &item.created, &item.event_type, &item.event_count.to_i64().expect("should have i64"), &item.event_payout.to_i64().expect("should have i64"), &item.earner]).await {
154155
err = Some(e);
155156
break;
156157
}

sentry/src/middleware/auth.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ fn get_request_ip(req: &Request<Body>) -> Option<String> {
7575
.get("true-client-ip")
7676
.or_else(|| req.headers().get("x-forwarded-for"))
7777
.and_then(|hv| hv.to_str().map(ToString::to_string).ok())
78-
.map(|token| {
79-
token
80-
.split(',')
81-
.nth(0)
82-
.map(ToString::to_string)
83-
})
78+
.map(|token| token.split(',').nth(0).map(ToString::to_string))
8479
.flatten()
8580
}
8681

sentry/src/routes/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub async fn insert_events<A: Adapter + 'static>(
128128
.ok_or_else(|| ResponseError::BadRequest("invalid request".to_string()))?;
129129

130130
app.event_aggregator
131-
.record(app, &channel, &session, &events.as_slice())
131+
.record(app, &channel, &session, &events)
132132
.await?;
133133

134134
Ok(Response::builder()

0 commit comments

Comments
 (0)