Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Dec 9, 2024
1 parent 78c519f commit 4f4cc9b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
5 changes: 3 additions & 2 deletions mobile_config/src/gateway_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub(crate) mod db {
pub async fn get_updated_radios(
db: impl PgExecutor<'_>,
min_updated_at: DateTime<Utc>,
) -> anyhow::Result<HashSet<String>> {
) -> anyhow::Result<HashSet<PublicKeyBinary>> {
let rows: Vec<Vec<u8>> = sqlx::query_scalar(GET_UPDATED_RADIOS)
.bind(min_updated_at)
.fetch_all(db)
Expand All @@ -392,7 +392,8 @@ pub(crate) mod db {
for row in rows {
let entity_key_b: &[u8] = &row;
let entity_key = bs58::encode(entity_key_b).into_string();
radios.insert(entity_key);
let pk = PublicKeyBinary::from_str(&entity_key)?;
radios.insert(pk);
}

Ok(radios)
Expand Down
3 changes: 1 addition & 2 deletions mobile_config/src/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ impl mobile_config::Gateway for GatewayService {
tokio::spawn(async move {
let stream = gateway_info::db::all_info_stream(&pool, &device_types);
if request.min_updated_at > 0 {
// It needs filtering only updated radios
let min_updated_at = Utc
.timestamp_opt(request.min_updated_at as i64, 0)
.single()
Expand All @@ -224,7 +223,7 @@ impl mobile_config::Gateway for GatewayService {

let updated_redios = get_updated_radios(&mc_pool, min_updated_at).await?;
let stream = stream
.filter(|v| future::ready(updated_redios.contains(&v.address.to_string())))
.filter(|v| future::ready(updated_redios.contains(&v.address)))
.boxed();
stream_multi_gateways_info(stream, tx.clone(), signing_key.clone(), batch_size)
.await
Expand Down
2 changes: 0 additions & 2 deletions mobile_config/tests/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async fn gateway_info_authorization_errors(pool: PgPool) -> anyhow::Result<()> {
// Start the gateway server
let keys = CacheKeys::from_iter([(admin_key.public_key().to_owned(), KeyRole::Administrator)]);
let (_key_cache_tx, key_cache) = KeyCache::new(keys);
// TODO
let gws = GatewayService::new(key_cache, pool.clone(), server_key, pool.clone());
let _handle = tokio::spawn(
transport::Server::builder()
Expand Down Expand Up @@ -99,7 +98,6 @@ async fn spawn_gateway_service(
// Start the gateway server
let keys = CacheKeys::from_iter([(admin_pub_key.to_owned(), KeyRole::Administrator)]);
let (_key_cache_tx, key_cache) = KeyCache::new(keys);
// TODO
let gws = GatewayService::new(key_cache, pool.clone(), server_key, pool.clone());
let handle = tokio::spawn(
transport::Server::builder()
Expand Down

0 comments on commit 4f4cc9b

Please sign in to comment.