Skip to content

Commit

Permalink
Clear older events
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Aug 7, 2024
1 parent 746554d commit 6d9231c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ where
data_session::clear_hotspot_data_sessions(&mut transaction, &reward_period.start).await?;
coverage::clear_coverage_objects(&mut transaction, &reward_period.start).await?;
sp_boosted_rewards_bans::clear_bans(&mut transaction, reward_period.start).await?;
subscriber_verified_mapping_event::clear(&mut transaction, &reward_period.end).await?;
// subscriber_location::clear_location_shares(&mut transaction, &reward_period.end).await?;

let next_reward_period = scheduler.next_reward_period();
Expand Down
15 changes: 14 additions & 1 deletion mobile_verifier/src/subscriber_verified_mapping_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub async fn aggregate_verified_mapping_events(
subscriber_id,
SUM(total_reward_points) AS total_reward_points
FROM
verified_subscriber_verified_mapping_event
verified_subscriber_verified_mapping_event
WHERE received_timestamp >= $1 AND received_timestamp < $2
GROUP BY
subscriber_id;",
Expand All @@ -277,3 +277,16 @@ pub async fn aggregate_verified_mapping_events(

Ok(vsme_shares)
}

pub async fn clear(
tx: &mut sqlx::Transaction<'_, sqlx::Postgres>,
timestamp: &DateTime<Utc>,
) -> Result<(), sqlx::Error> {
sqlx::query(
"DELETE FROM verified_subscriber_verified_mapping_event WHERE received_timestamp < $1",
)
.bind(timestamp)
.execute(&mut *tx)
.await?;
Ok(())
}

0 comments on commit 6d9231c

Please sign in to comment.