Skip to content

Commit

Permalink
Merge pull request #386 from helium/bbalser/update-mainnet-iot-query
Browse files Browse the repository at this point in the history
Update query to pull beacons from db
  • Loading branch information
madninja authored Feb 25, 2023
2 parents 91462f0 + 56357ff commit 59d648e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions iot_verifier/src/poc_report.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::entropy::ENTROPY_LIFESPAN;
use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -194,7 +193,6 @@ impl Report {
where
E: sqlx::Executor<'c, Database = sqlx::Postgres>,
{
let entropy_min_time = Utc::now() - Duration::seconds(ENTROPY_LIFESPAN);
Ok(sqlx::query_as::<_, Self>(
r#"
select poc_report.id,
Expand All @@ -210,15 +208,18 @@ impl Report {
entropy.timestamp,
entropy.version
from poc_report
inner join entropy on poc_report.remote_entropy=entropy.data
left join entropy on entropy.id = (select ie.id
from entropy as ie
where poc_report.remote_entropy = ie.data and
poc_report.report_timestamp >= ie.timestamp and
poc_report.report_timestamp <= ie.timestamp + interval '3 minutes'
limit 1)
where poc_report.report_type = 'beacon' and status = 'ready'
and entropy.timestamp < $1
and poc_report.attempts < $2
and poc_report.attempts < $1
order by poc_report.created_at asc
limit 25000
"#,
)
.bind(entropy_min_time)
.bind(BEACON_MAX_RETRY_ATTEMPTS)
.fetch_all(executor)
.await?)
Expand Down

0 comments on commit 59d648e

Please sign in to comment.