diff --git a/packages/backend-rs/src/service/antenna/add_new_note.rs b/packages/backend-rs/src/service/antenna/add_new_note.rs index 4cf238a8db..1d2d336766 100644 --- a/packages/backend-rs/src/service/antenna/add_new_note.rs +++ b/packages/backend-rs/src/service/antenna/add_new_note.rs @@ -36,11 +36,13 @@ type Note = note::Model; async fn antennas() -> Result, Error> { const CACHE_KEY: &str = "antennas"; - Ok(cache::get::>(CACHE_KEY).await?.unwrap_or({ + if let Some(antennas) = cache::get::>(CACHE_KEY).await? { + Ok(antennas) + } else { let antennas = antenna::Entity::find().all(db_conn().await?).await?; cache::set(CACHE_KEY, &antennas, 5 * 60).await?; - antennas - })) + Ok(antennas) + } } #[crate::export] diff --git a/packages/backend-rs/src/service/antenna/check_hit.rs b/packages/backend-rs/src/service/antenna/check_hit.rs index 44b729aa26..e43eae2aee 100644 --- a/packages/backend-rs/src/service/antenna/check_hit.rs +++ b/packages/backend-rs/src/service/antenna/check_hit.rs @@ -94,9 +94,10 @@ pub async fn check_hit_antenna( let db = db_conn().await?; - let blocked_user_ids: Vec = cache::get_one(cache::Category::Block, ¬e.user_id) - .await? - .unwrap_or({ + let blocked_user_ids: Vec = + if let Some(ids) = cache::get_one(cache::Category::Block, ¬e.user_id).await? { + ids + } else { // cache miss let blocks = blocking::Entity::find() .select_only() @@ -107,7 +108,7 @@ pub async fn check_hit_antenna( .await?; cache::set_one(cache::Category::Block, ¬e.user_id, &blocks, 10 * 60).await?; blocks - }); + }; // if the antenna owner is blocked by the note author, return false if blocked_user_ids.contains(&antenna.user_id) { @@ -116,26 +117,26 @@ pub async fn check_hit_antenna( if [NoteVisibilityEnum::Home, NoteVisibilityEnum::Followers].contains(¬e.visibility) { let following_user_ids: Vec = - cache::get_one(cache::Category::Follow, &antenna.user_id) - .await? - .unwrap_or({ - // cache miss - let following = following::Entity::find() - .select_only() - .column(following::Column::FolloweeId) - .filter(following::Column::FollowerId.eq(&antenna.user_id)) - .into_tuple::() - .all(db) - .await?; - cache::set_one( - cache::Category::Follow, - &antenna.user_id, - &following, - 10 * 60, - ) + if let Some(ids) = cache::get_one(cache::Category::Follow, &antenna.user_id).await? { + ids + } else { + // cache miss + let following = following::Entity::find() + .select_only() + .column(following::Column::FolloweeId) + .filter(following::Column::FollowerId.eq(&antenna.user_id)) + .into_tuple::() + .all(db) .await?; - following - }); + cache::set_one( + cache::Category::Follow, + &antenna.user_id, + &following, + 10 * 60, + ) + .await?; + following + }; // if the antenna owner is not following the note author, return false if !following_user_ids.contains(¬e.user_id) {