From 0a32b1980dee536b605729b33a70732988050af2 Mon Sep 17 00:00:00 2001 From: Matthew Plant Date: Mon, 11 Sep 2023 10:53:52 -0400 Subject: [PATCH] Check if hex_coverage is empty in coalesce --- mobile_verifier/src/coverage.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mobile_verifier/src/coverage.rs b/mobile_verifier/src/coverage.rs index dab1188c8..031d63789 100644 --- a/mobile_verifier/src/coverage.rs +++ b/mobile_verifier/src/coverage.rs @@ -14,6 +14,7 @@ use futures::{ stream::{BoxStream, Stream, StreamExt}, TryFutureExt, TryStreamExt, }; +use futures_util::stream; use h3o::{CellIndex, LatLng}; use helium_crypto::PublicKeyBinary; use helium_proto::services::{ @@ -349,14 +350,19 @@ impl CoveredHexStream for Pool { .await?; // Find the time of insertion for the currently in use coverage object - let current_inserted_at: DateTime = sqlx::query_scalar( + let current_inserted_at: Option> = sqlx::query_scalar( "SELECT inserted_at FROM hex_coverage WHERE cbsd_id = $1 AND uuid = $2 LIMIT 1", ) .bind(cbsd_id) .bind(coverage_obj) - .fetch_one(self) + .fetch_optional(self) .await?; + // If we don't have an inserted_at, we don't have any hex coverage + let Some(current_inserted_at) = current_inserted_at else { + return Ok(stream::empty().boxed()); + }; + // Delete any hex coverages that were inserted before the one we are currently using, as they are // no longer useful. sqlx::query(