Skip to content

Commit

Permalink
Fix radio threshold indexes and insert to not use Posgres 15 feature (#…
Browse files Browse the repository at this point in the history
…755)

* Fix radio threshold indexes and insert

* Fix query for grandfathered radios
  • Loading branch information
bbalser authored Mar 8, 2024
1 parent 6d46823 commit e9a6801
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mobile_verifier/migrations/27_subscriber_radio_threshold.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS radio_threshold (
created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE UNIQUE INDEX IF NOT EXISTS radio_threshold_hotspot_pubkey_cbsd_id_idx ON radio_threshold (hotspot_pubkey, cbsd_id) NULLS NOT DISTINCT;
CREATE UNIQUE INDEX IF NOT EXISTS radio_threshold_hotspot_pubkey_cbsd_id_idx ON radio_threshold (hotspot_pubkey, COALESCE(cbsd_id,''));

-- temp table for grandfathered radio thresholds
CREATE TABLE IF NOT EXISTS grandfathered_radio_threshold (
Expand All @@ -21,4 +21,4 @@ CREATE TABLE IF NOT EXISTS grandfathered_radio_threshold (
created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE UNIQUE INDEX IF NOT EXISTS grandfathered_radio_threshold_hotspot_pubkey_cbsd_id_idx ON grandfathered_radio_threshold (hotspot_pubkey, cbsd_id) NULLS NOT DISTINCT;
CREATE UNIQUE INDEX IF NOT EXISTS grandfathered_radio_threshold_hotspot_pubkey_cbsd_id_idx ON grandfathered_radio_threshold (hotspot_pubkey, COALESCE(cbsd_id,''));
4 changes: 2 additions & 2 deletions mobile_verifier/src/radio_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ where
// boosted rewards prior to the data component of hip84 going live
// if true then it is assigned a status reason of Legacy
// TODO: remove this handling after the grandfathering period
let row = sqlx::query(" select exists(select 1 from grandfathered_radio_threshold where hotspot_key = $1 and cbsd_id = $2) ")
let row = sqlx::query(" select exists(select 1 from grandfathered_radio_threshold where hotspot_pubkey = $1 and (cbsd_id is null or cbsd_id = $2)) ")
.bind(hotspot_key)
.bind(cbsd_id)
.fetch_one(&self.pool)
Expand All @@ -194,7 +194,7 @@ pub async fn save(
threshold_met,
recv_timestamp)
VALUES ($1, $2, $3, $4, $5, true, $6)
ON CONFLICT (hotspot_pubkey, cbsd_id)
ON CONFLICT (hotspot_pubkey, COALESCE(cbsd_id, ''))
DO UPDATE SET
bytes_threshold = EXCLUDED.bytes_threshold,
subscriber_threshold = EXCLUDED.subscriber_threshold,
Expand Down

0 comments on commit e9a6801

Please sign in to comment.