diff --git a/packages/backend-rs/src/service/antenna/cache.rs b/packages/backend-rs/src/service/antenna/cache.rs index 65bd6efca9..ce83895368 100644 --- a/packages/backend-rs/src/service/antenna/cache.rs +++ b/packages/backend-rs/src/service/antenna/cache.rs @@ -2,24 +2,23 @@ use crate::{database::db_conn, model::entity::antenna}; use sea_orm::prelude::*; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; -static CACHE: Mutex>> = Mutex::new(None); +static CACHE: Mutex>> = Mutex::new(None); -fn set(antennas: &[antenna::Model]) { - let _ = CACHE - .lock() - .map(|mut cache| *cache = Some(antennas.to_owned())); +fn set(antennas: Arc<[antenna::Model]>) { + let _ = CACHE.lock().map(|mut cache| *cache = Some(antennas)); } -pub(super) async fn update() -> Result, DbErr> { +pub(super) async fn update() -> Result, DbErr> { tracing::debug!("updating cache"); - let antennas = antenna::Entity::find().all(db_conn().await?).await?; - set(&antennas); + let antennas: Arc<[antenna::Model]> = + antenna::Entity::find().all(db_conn().await?).await?.into(); + set(antennas.clone()); Ok(antennas) } -pub(super) async fn get() -> Result, DbErr> { +pub(super) async fn get() -> Result, DbErr> { if let Some(cache) = CACHE.lock().ok().and_then(|cache| cache.clone()) { return Ok(cache); } diff --git a/packages/backend-rs/src/service/antenna/check_hit.rs b/packages/backend-rs/src/service/antenna/check_hit.rs index 0f297ccbb2..fff8962ed4 100644 --- a/packages/backend-rs/src/service/antenna/check_hit.rs +++ b/packages/backend-rs/src/service/antenna/check_hit.rs @@ -12,8 +12,6 @@ pub enum AntennaCheckError { Db(#[from] DbErr), #[error("Cache error: {0}")] Cache(#[from] cache::Error), - #[error("User profile not found: {0}")] - UserProfileNotFound(String), } fn match_all(space_separated_words: &str, text: &str, case_sensitive: bool) -> bool { @@ -29,7 +27,7 @@ fn match_all(space_separated_words: &str, text: &str, case_sensitive: bool) -> b } } -pub async fn check_hit_antenna( +pub(super) async fn check_hit_antenna( antenna: &antenna::Model, note: ¬e::Model, note_all_texts: &[String], diff --git a/packages/backend-rs/src/service/antenna/process_new_note.rs b/packages/backend-rs/src/service/antenna/process_new_note.rs index b9eed0eff8..9e63b6065d 100644 --- a/packages/backend-rs/src/service/antenna/process_new_note.rs +++ b/packages/backend-rs/src/service/antenna/process_new_note.rs @@ -37,19 +37,18 @@ type Note = note::Model; #[crate::export] pub async fn update_antennas_on_new_note( - note: Note, + note: &Note, note_author: &Acct, note_muted_users: &[String], ) -> Result<(), Error> { - let note_cloned = note.clone(); let note_all_texts = all_texts( PartialNoteToElaborate { - file_ids: note.file_ids, - user_id: note.user_id, - text: note.text, - cw: note.cw, - renote_id: note.renote_id, - reply_id: note.reply_id, + file_ids: note.file_ids.to_owned(), + user_id: note.user_id.to_owned(), + text: note.text.to_owned(), + cw: note.cw.to_owned(), + renote_id: note.renote_id.to_owned(), + reply_id: note.reply_id.to_owned(), }, false, ) @@ -60,8 +59,8 @@ pub async fn update_antennas_on_new_note( if note_muted_users.contains(&antenna.user_id) { continue; } - if check_hit_antenna(antenna, ¬e_cloned, ¬e_all_texts, note_author).await? { - add_note_to_antenna(&antenna.id, ¬e_cloned).await?; + if check_hit_antenna(antenna, note, ¬e_all_texts, note_author).await? { + add_note_to_antenna(&antenna.id, note).await?; } }