Skip to content

Commit 55ea459

Browse files
committed
Improvements on docs, benching & analytics recording
1 parent 96734ad commit 55ea459

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

sentry/Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ args = [
5252
"-t3",
5353
"-c100",
5454
"-d30s",
55-
"-R2000",
55+
"-R3000",
5656
"--latency",
5757
"http://127.0.0.1:8005/v5/campaign",
5858
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CREATE TABLE accounting (
7272
side AccountingSide NOT NULL,
7373
"address" varchar(42) NOT NULL,
7474
amount bigint NOT NULL,
75-
updated timestamp(2) with time zone DEFAULT NULL NULL,
75+
updated timestamp(2) with time zone DEFAULT NULL,
7676
created timestamp(2) with time zone NOT NULL,
7777
-- Do not rename the Primary key constraint (`accounting_pkey`)!
7878
PRIMARY KEY (channel_id, side, "address"),

sentry/src/access.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub async fn check_access(
4242
return Err(Error::ForbiddenReferrer);
4343
}
4444

45+
// Used when `Campaign::event_submission` is `None`
4546
let default_rules = [
4647
Rule {
4748
uids: Some(vec![campaign.creator.to_string()]),
@@ -84,7 +85,7 @@ pub async fn check_access(
8485
}
8586

8687
async fn apply_rule(
87-
redis: MultiplexedConnection,
88+
mut redis: MultiplexedConnection,
8889
rule: &Rule,
8990
events: &[Event],
9091
campaign: &Campaign,
@@ -116,7 +117,7 @@ async fn apply_rule(
116117

117118
if redis::cmd("EXISTS")
118119
.arg(&key)
119-
.query_async::<_, i8>(&mut redis.clone())
120+
.query_async::<_, i8>(&mut redis)
120121
.await
121122
.map(|exists| exists == 1)
122123
.map_err(|error| format!("{}", error))?
@@ -129,7 +130,7 @@ async fn apply_rule(
129130
.arg(&key)
130131
.arg(seconds as i32)
131132
.arg("1")
132-
.query_async::<_, ()>(&mut redis.clone())
133+
.query_async::<_, ()>(&mut redis)
133134
.await
134135
.map_err(|error| format!("{}", error))
135136
}

sentry/src/analytics.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
db::{analytics::update_analytics, DbPool, PoolError},
33
Session,
44
};
5+
use futures::future::join_all;
56
use primitives::{
67
analytics::OperatingSystem,
78
sentry::{DateHour, Event, UpdateAnalytics},
@@ -14,7 +15,7 @@ pub async fn record(
1415
pool: &DbPool,
1516
campaign_context: &ChainOf<Campaign>,
1617
session: &Session,
17-
events_with_payouts: Vec<(Event, Address, UnifiedNum)>,
18+
events_with_payouts: &[(Event, Address, UnifiedNum)],
1819
) -> Result<(), PoolError> {
1920
let os_name = session
2021
.os
@@ -65,7 +66,7 @@ pub async fn record(
6566
};
6667

6768
batch_update
68-
.entry(event)
69+
.entry(event.clone())
6970
.and_modify(|analytics| {
7071
analytics.amount_to_add += &payout_amount;
7172
analytics.count_to_add += 1;
@@ -83,14 +84,24 @@ pub async fn record(
8384
os_name: os_name.clone(),
8485
chain_id: campaign_context.chain.chain_id,
8586
event_type,
86-
amount_to_add: payout_amount,
87+
amount_to_add: *payout_amount,
8788
count_to_add: 1,
8889
});
8990
}
9091

91-
for (_event, update) in batch_update.into_iter() {
92-
update_analytics(pool, update).await?;
93-
}
92+
let batch_futures = join_all(
93+
batch_update
94+
.into_iter()
95+
.map(|(_event, update)| update_analytics(pool, update)),
96+
);
97+
98+
// execute the batched futures, collect the result afterwards,
99+
// in order execute all futures first and then return an error if occurred
100+
batch_futures
101+
.await
102+
.into_iter()
103+
.collect::<Result<Vec<_>, _>>()?;
104+
94105
Ok(())
95106
}
96107

@@ -192,7 +203,7 @@ mod test {
192203
let channel_context = channel_chain.with_channel(dummy_channel);
193204
let campaign_context = channel_context.clone().with(campaign);
194205

195-
record(&app.pool, &campaign_context, &session, input_events.clone())
206+
record(&app.pool, &campaign_context, &session, &input_events)
196207
.await
197208
.expect("should record");
198209

@@ -256,7 +267,7 @@ mod test {
256267
.expect("Channel token should be whitelisted in config!");
257268
let channel_context = channel_chain.with_channel(dummy_channel);
258269
let campaign_context = channel_context.clone().with(campaign);
259-
record(&app.pool, &campaign_context, &session, input_events.clone())
270+
record(&app.pool, &campaign_context, &session, &input_events)
260271
.await
261272
.expect("should record");
262273

0 commit comments

Comments
 (0)