fix (backend-rs): wrong unwrap_or usage
This commit is contained in:
parent
97d0a21312
commit
b24530065e
2 changed files with 29 additions and 26 deletions
|
@ -36,11 +36,13 @@ type Note = note::Model;
|
||||||
async fn antennas() -> Result<Vec<Antenna>, Error> {
|
async fn antennas() -> Result<Vec<Antenna>, Error> {
|
||||||
const CACHE_KEY: &str = "antennas";
|
const CACHE_KEY: &str = "antennas";
|
||||||
|
|
||||||
Ok(cache::get::<Vec<Antenna>>(CACHE_KEY).await?.unwrap_or({
|
if let Some(antennas) = cache::get::<Vec<Antenna>>(CACHE_KEY).await? {
|
||||||
|
Ok(antennas)
|
||||||
|
} else {
|
||||||
let antennas = antenna::Entity::find().all(db_conn().await?).await?;
|
let antennas = antenna::Entity::find().all(db_conn().await?).await?;
|
||||||
cache::set(CACHE_KEY, &antennas, 5 * 60).await?;
|
cache::set(CACHE_KEY, &antennas, 5 * 60).await?;
|
||||||
antennas
|
Ok(antennas)
|
||||||
}))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::export]
|
#[crate::export]
|
||||||
|
|
|
@ -94,9 +94,10 @@ pub async fn check_hit_antenna(
|
||||||
|
|
||||||
let db = db_conn().await?;
|
let db = db_conn().await?;
|
||||||
|
|
||||||
let blocked_user_ids: Vec<String> = cache::get_one(cache::Category::Block, ¬e.user_id)
|
let blocked_user_ids: Vec<String> =
|
||||||
.await?
|
if let Some(ids) = cache::get_one(cache::Category::Block, ¬e.user_id).await? {
|
||||||
.unwrap_or({
|
ids
|
||||||
|
} else {
|
||||||
// cache miss
|
// cache miss
|
||||||
let blocks = blocking::Entity::find()
|
let blocks = blocking::Entity::find()
|
||||||
.select_only()
|
.select_only()
|
||||||
|
@ -107,7 +108,7 @@ pub async fn check_hit_antenna(
|
||||||
.await?;
|
.await?;
|
||||||
cache::set_one(cache::Category::Block, ¬e.user_id, &blocks, 10 * 60).await?;
|
cache::set_one(cache::Category::Block, ¬e.user_id, &blocks, 10 * 60).await?;
|
||||||
blocks
|
blocks
|
||||||
});
|
};
|
||||||
|
|
||||||
// if the antenna owner is blocked by the note author, return false
|
// if the antenna owner is blocked by the note author, return false
|
||||||
if blocked_user_ids.contains(&antenna.user_id) {
|
if blocked_user_ids.contains(&antenna.user_id) {
|
||||||
|
@ -116,9 +117,9 @@ pub async fn check_hit_antenna(
|
||||||
|
|
||||||
if [NoteVisibilityEnum::Home, NoteVisibilityEnum::Followers].contains(¬e.visibility) {
|
if [NoteVisibilityEnum::Home, NoteVisibilityEnum::Followers].contains(¬e.visibility) {
|
||||||
let following_user_ids: Vec<String> =
|
let following_user_ids: Vec<String> =
|
||||||
cache::get_one(cache::Category::Follow, &antenna.user_id)
|
if let Some(ids) = cache::get_one(cache::Category::Follow, &antenna.user_id).await? {
|
||||||
.await?
|
ids
|
||||||
.unwrap_or({
|
} else {
|
||||||
// cache miss
|
// cache miss
|
||||||
let following = following::Entity::find()
|
let following = following::Entity::find()
|
||||||
.select_only()
|
.select_only()
|
||||||
|
@ -135,7 +136,7 @@ pub async fn check_hit_antenna(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
following
|
following
|
||||||
});
|
};
|
||||||
|
|
||||||
// if the antenna owner is not following the note author, return false
|
// if the antenna owner is not following the note author, return false
|
||||||
if !following_user_ids.contains(¬e.user_id) {
|
if !following_user_ids.contains(¬e.user_id) {
|
||||||
|
|
Loading…
Reference in a new issue