diff --git a/mobile_config/src/gateway_info.rs b/mobile_config/src/gateway_info.rs index f57568c08..c5fed2a03 100644 --- a/mobile_config/src/gateway_info.rs +++ b/mobile_config/src/gateway_info.rs @@ -134,7 +134,8 @@ pub(crate) mod db { use std::str::FromStr; const GET_METADATA_SQL: &str = r#" - select kta.entity_key, infos.location::bigint, infos.device_type + select kta.entity_key, infos.location::bigint, infos.device_type, + infos.refreshed_at, infos.created_at from mobile_hotspot_infos infos join key_to_assets kta on infos.asset = kta.asset "#; @@ -179,6 +180,7 @@ pub(crate) mod db { pub fn all_info_stream<'a>( db: impl PgExecutor<'a> + 'a, device_types: &'a [DeviceType], + _min_refreshed_at: i64, // TODO ) -> impl Stream + 'a { match device_types.is_empty() { true => sqlx::query_as::<_, GatewayInfo>(GET_METADATA_SQL) @@ -213,17 +215,13 @@ pub(crate) mod db { .as_ref(), ) .map_err(|err| sqlx::Error::Decode(Box::new(err)))?; - let created_at = row.get::("created_at"); + let created_at = row.get::, &str>("created_at"); // `refreshed_at` can be NULL in the database schema. // If so, fallback to using `created_at` as the default value of `refreshed_at`. let refreshed_at = row - .get::, &str>("refreshed_at") + .get::>, &str>("refreshed_at") .unwrap_or(created_at); - // TODO remove unwraps - let created_at = DateTime::::from_timestamp(created_at, 0).unwrap(); - let refreshed_at = DateTime::::from_timestamp(refreshed_at, 0).unwrap(); - Ok(Self { address: PublicKeyBinary::from_str( &bs58::encode(row.get::<&[u8], &str>("entity_key")).into_string(), diff --git a/mobile_config/src/gateway_service.rs b/mobile_config/src/gateway_service.rs index 90f1a11f9..1bc518f8c 100644 --- a/mobile_config/src/gateway_service.rs +++ b/mobile_config/src/gateway_service.rs @@ -170,7 +170,11 @@ impl mobile_config::Gateway for GatewayService { ); tokio::spawn(async move { - let stream = gateway_info::db::all_info_stream(&pool, &device_types); + let stream = gateway_info::db::all_info_stream( + &pool, + &device_types, + request.min_refreshed_at as i64, + ); stream_multi_gateways_info(stream, tx.clone(), signing_key.clone(), batch_size).await }); diff --git a/mobile_config/tests/gateway_service.rs b/mobile_config/tests/gateway_service.rs index 07e22dd61..9bddbfe28 100644 --- a/mobile_config/tests/gateway_service.rs +++ b/mobile_config/tests/gateway_service.rs @@ -235,7 +235,9 @@ async fn create_db_tables(pool: &PgPool) { CREATE TABLE mobile_hotspot_infos ( asset character varying(255) NULL, location numeric NULL, - device_type jsonb NOT NULL + device_type jsonb NOT NULL, + created_at timestamptz NOT NULL DEFAULT NOW(), + refreshed_at timestamptz );"#, ) .execute(pool)