Skip to content

Commit

Permalink
purge old speedtests from db
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Jul 27, 2023
1 parent cef6f7e commit af05140
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
data_session,
heartbeats::HeartbeatReward,
reward_shares::{MapperShares, PocShares, TransferRewards},
speedtests_average::SpeedtestAverages,
speedtests_average::{SpeedtestAverages, SPEEDTEST_LAPSE},
subscriber_location, telemetry,
};
use anyhow::bail;
Expand Down Expand Up @@ -237,6 +237,14 @@ impl Rewarder {
.execute(&mut transaction)
.await?;

// Clear the speedtests table of tests older than hours defined by SPEEDTEST_LAPSE
// We end up with tests older than we need here but erroring on side of caution
// and the volume of tests is low so no big impact there
sqlx::query("DELETE FROM speedtests timestamp < $1")
.bind(Utc::now() - Duration::hours(SPEEDTEST_LAPSE))
.execute(&mut transaction)
.await?;

// clear the db of data sessions data & subscriber location data for the epoch
data_session::clear_hotspot_data_sessions(&mut transaction, reward_period).await?;
subscriber_location::clear_location_shares(&mut transaction, reward_period).await?;
Expand Down
2 changes: 1 addition & 1 deletion mobile_verifier/src/speedtests_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sqlx::FromRow;

use std::collections::HashMap;

const SPEEDTEST_LAPSE: i64 = 48;
pub const SPEEDTEST_LAPSE: i64 = 48;
const MIN_DOWNLOAD: u64 = mbps(30);
const MIN_UPLOAD: u64 = mbps(2);
const MAX_LATENCY: u32 = 100;
Expand Down

0 comments on commit af05140

Please sign in to comment.