diff --git a/src/cache/cache.rs b/src/cache/cache.rs index 9ff586c3..536ce5f6 100644 --- a/src/cache/cache.rs +++ b/src/cache/cache.rs @@ -30,7 +30,7 @@ pub struct Cache { // discord side pub guilds: AsyncDashMap, CachedGuild>, pub users: AsyncDashMap, Option>>, - pub messages: stretto::AsyncCache, Arc>>, + pub messages: stretto::AsyncCache, Option>>, // database side pub autostar_channel_ids: AsyncDashSet>, @@ -182,7 +182,7 @@ impl Cache { bot: &StarboardBot, channel_id: Id, message_id: Id, - ) -> StarboardResult>> { + ) -> StarboardResult>> { if let Some(cached) = self.messages.get(&message_id) { return Ok(cached.value().clone()); } @@ -196,10 +196,10 @@ impl Cache { return Err(why.into()); } } - Ok(msg) => Some(msg.model().await.unwrap().into()), + Ok(msg) => Some(Arc::new(msg.model().await.unwrap().into())), }; - self.messages.insert(message_id, Arc::new(msg), 1).await; + self.messages.insert(message_id, msg, 1).await; self.messages.wait().await.unwrap(); Ok(self.messages.get(&message_id).unwrap().value().clone()) diff --git a/src/cache/events/message.rs b/src/cache/events/message.rs index bed51252..076225e4 100644 --- a/src/cache/events/message.rs +++ b/src/cache/events/message.rs @@ -18,7 +18,7 @@ impl UpdateCache for MessageCreate { let message = CachedMessage::from(&self.0); cache .messages - .insert(self.id, Arc::new(Some(message)), 1) + .insert(self.id, Some(Arc::new(message)), 1) .await; } } @@ -26,7 +26,7 @@ impl UpdateCache for MessageCreate { #[async_trait] impl UpdateCache for MessageDelete { async fn update_cache(&self, cache: &Cache) { - cache.messages.insert(self.id, Arc::new(None), 1).await; + cache.messages.insert(self.id, None, 1).await; } } @@ -34,7 +34,7 @@ impl UpdateCache for MessageDelete { impl UpdateCache for MessageDeleteBulk { async fn update_cache(&self, cache: &Cache) { for id in &self.ids { - cache.messages.insert(*id, Arc::new(None), 1).await; + cache.messages.insert(*id, None, 1).await; } } } @@ -47,11 +47,11 @@ impl UpdateCache for MessageUpdate { match cached { None => return, - Some(ref msg) => msg.value().clone(), + Some(msg) => msg.value().clone(), } }; - let cached = match &*cached { + let cached = match cached { None => { cache.messages.remove(&self.id).await; return; @@ -86,7 +86,7 @@ impl UpdateCache for MessageUpdate { cache .messages - .insert(self.id, Arc::new(Some(message)), 1) + .insert(self.id, Some(Arc::new(message)), 1) .await; } } diff --git a/src/core/autostar.rs b/src/core/autostar.rs index b393ee99..271d6435 100644 --- a/src/core/autostar.rs +++ b/src/core/autostar.rs @@ -112,8 +112,7 @@ async fn get_status(bot: &StarboardBot, asc: &AutoStarChannel, event: &MessageCr let mut still_invalid = true; if let Some(msg) = updated_msg { - let msg = msg.value().clone(); - let msg = match &*msg { + let msg = match msg.value() { None => return Status::InvalidStay, Some(msg) => msg, }; diff --git a/src/core/embedder/builder.rs b/src/core/embedder/builder.rs index b4ce462d..848ec4e1 100644 --- a/src/core/embedder/builder.rs +++ b/src/core/embedder/builder.rs @@ -31,7 +31,7 @@ pub enum BuiltStarboardEmbed { impl BuiltStarboardEmbed { pub fn build(handle: &Embedder) -> Self { - let orig = match &*handle.orig_message { + let orig = match &handle.orig_message { None => { return Self::Partial(PartialBuiltStarboardEmbed { top_content: Self::build_top_content(handle), @@ -96,7 +96,7 @@ impl BuiltStarboardEmbed { } pub fn build_replied_embed(handle: &Embedder) -> Option { - let ref_msg = match &*handle.referenced_message { + let ref_msg = match &handle.referenced_message { None => return None, Some(msg) => msg, }; diff --git a/src/core/embedder/handle.rs b/src/core/embedder/handle.rs index 9abf8bc2..75b53e0d 100644 --- a/src/core/embedder/handle.rs +++ b/src/core/embedder/handle.rs @@ -14,9 +14,9 @@ use super::{attachment_handle::VecAttachments, builder::BuiltStarboardEmbed}; pub struct Embedder<'config> { pub points: i32, pub config: &'config StarboardConfig, - pub orig_message: Arc>, + pub orig_message: Option>, pub orig_message_author: Option>, - pub referenced_message: Arc>, + pub referenced_message: Option>, pub referenced_message_author: Option>, pub orig_sql_message: Arc, } @@ -25,9 +25,9 @@ impl<'config> Embedder<'config> { pub fn new( points: i32, config: &'config StarboardConfig, - orig_message: Arc>, + orig_message: Option>, orig_message_author: Option>, - referenced_message: Arc>, + referenced_message: Option>, referenced_message_author: Option>, orig_sql_message: Arc, ) -> Self { diff --git a/src/core/starboard/handle.rs b/src/core/starboard/handle.rs index 91fb87b2..9566e4e4 100644 --- a/src/core/starboard/handle.rs +++ b/src/core/starboard/handle.rs @@ -22,7 +22,7 @@ pub struct RefreshMessage<'bot> { /// The id of the inputted message. May or may not be the original. message_id: Id, sql_message: Option>, - orig_message: Option>>, + orig_message: Option>>, configs: Option>>, } @@ -86,11 +86,11 @@ impl RefreshMessage<'_> { Ok(self.sql_message.as_ref().unwrap().clone()) } - pub fn set_orig_message(&mut self, message: Arc>) { + pub fn set_orig_message(&mut self, message: Option>) { self.orig_message.replace(message); } - async fn get_orig_message(&mut self) -> StarboardResult>> { + async fn get_orig_message(&mut self) -> StarboardResult>> { if self.orig_message.is_none() { let sql_message = self.get_sql_message().await?; let orig_message = self @@ -153,7 +153,7 @@ impl<'this, 'bot> RefreshStarboard<'this, 'bot> { .cache .fog_user(self.refresh.bot, Id::new(sql_message.author_id as u64)) .await?; - let (ref_msg, ref_msg_author) = if let Some(msg) = &*orig_message { + let (ref_msg, ref_msg_author) = if let Some(msg) = &orig_message { if let Some(id) = msg.referenced_message { let ref_msg = self .refresh @@ -162,7 +162,7 @@ impl<'this, 'bot> RefreshStarboard<'this, 'bot> { .fog_message(self.refresh.bot, Id::new(sql_message.channel_id as u64), id) .await?; - let ref_msg_author = match &*ref_msg { + let ref_msg_author = match &ref_msg { None => None, Some(ref_msg) => Some( self.refresh @@ -175,10 +175,10 @@ impl<'this, 'bot> RefreshStarboard<'this, 'bot> { (ref_msg, ref_msg_author.flatten()) } else { - (Arc::new(None), None) + (None, None) } } else { - (Arc::new(None), None) + (None, None) }; let embedder = Embedder::new( diff --git a/src/core/starboard/reaction_events.rs b/src/core/starboard/reaction_events.rs index 407ac59d..6aed25b2 100644 --- a/src/core/starboard/reaction_events.rs +++ b/src/core/starboard/reaction_events.rs @@ -48,7 +48,7 @@ pub async fn handle_reaction_add( .cache .fog_message(bot, event.channel_id, event.message_id) .await?; - let orig_msg_obj = match &*orig_msg_obj { + let orig_msg_obj = match orig_msg_obj { None => return Ok(()), Some(obj) => obj, };