Update cached channel state from notifications.
This commit is contained in:
@@ -139,36 +139,54 @@ impl<'r> FromParam<'r> for Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn test() {
|
use crate::notifications::events::Notification;
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
let now = Instant::now();
|
pub fn process_event(event: &Notification) {
|
||||||
let mut cache = CACHE.lock().unwrap();
|
match event {
|
||||||
println!("I'm about to write 4 million entries to cache.");
|
Notification::group_user_join(ev) => {
|
||||||
for i in 0..4_000_000 {
|
let mut cache = CACHE.lock().unwrap();
|
||||||
let c = Channel {
|
let entry = cache.pop(&ev.id);
|
||||||
id: "potato".to_string(),
|
|
||||||
channel_type: 0,
|
|
||||||
|
|
||||||
active: None,
|
if entry.is_some() {
|
||||||
last_message: None,
|
let mut channel = entry.unwrap();
|
||||||
description: None,
|
channel.recipients.as_mut().unwrap().push(ev.user.clone());
|
||||||
guild: None,
|
cache.put(ev.id.clone(), channel);
|
||||||
name: None,
|
}
|
||||||
owner: None,
|
}
|
||||||
recipients: None
|
Notification::group_user_leave(ev) => {
|
||||||
};
|
let mut cache = CACHE.lock().unwrap();
|
||||||
|
let entry = cache.pop(&ev.id);
|
||||||
|
|
||||||
cache.put(format!("{}", i), c);
|
if entry.is_some() {
|
||||||
|
let mut channel = entry.unwrap();
|
||||||
|
let recipients = channel.recipients.as_mut().unwrap();
|
||||||
|
if let Some(pos) = recipients.iter().position(|x| *x == ev.user) {
|
||||||
|
recipients.remove(pos);
|
||||||
|
}
|
||||||
|
cache.put(ev.id.clone(), channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Notification::guild_channel_create(ev) => {
|
||||||
|
let mut cache = CACHE.lock().unwrap();
|
||||||
|
cache.put(
|
||||||
|
ev.id.clone(),
|
||||||
|
Channel {
|
||||||
|
id: ev.channel.clone(),
|
||||||
|
channel_type: 2,
|
||||||
|
active: None,
|
||||||
|
last_message: None,
|
||||||
|
recipients: None,
|
||||||
|
owner: None,
|
||||||
|
guild: Some(ev.id.clone()),
|
||||||
|
name: Some(ev.name.clone()),
|
||||||
|
description: Some(ev.description.clone())
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Notification::guild_channel_delete(ev) => {
|
||||||
|
let mut cache = CACHE.lock().unwrap();
|
||||||
|
cache.pop(&ev.channel);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
println!("It took {} seconds, roughly {}ms per entry.", now.elapsed().as_secs_f64(), now.elapsed().as_millis() as f64 / 1_000_000.0);
|
|
||||||
|
|
||||||
let now = Instant::now();
|
|
||||||
println!("Now I'm going to read every entry and immediately dispose of it.");
|
|
||||||
for i in 0..4_000_000 {
|
|
||||||
cache.get(&format!("{}", i));
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("It took {} seconds, roughly {}ms per entry.", now.elapsed().as_secs_f64(), now.elapsed().as_millis() as f64 / 1_000_000.0);
|
|
||||||
}*/
|
|
||||||
|
|||||||
@@ -38,4 +38,8 @@ impl Notification {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn push_to_cache(&self) {
|
||||||
|
crate::database::channel::process_event(&self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ pub fn send_message<U: Into<Option<Vec<String>>>, G: Into<Option<String>>>(
|
|||||||
let users = users.into();
|
let users = users.into();
|
||||||
let guild = guild.into();
|
let guild = guild.into();
|
||||||
|
|
||||||
|
data.push_to_cache();
|
||||||
|
|
||||||
if pubsub::send_message(users.clone(), guild.clone(), data.clone()) {
|
if pubsub::send_message(users.clone(), guild.clone(), data.clone()) {
|
||||||
state::send_message(users, guild, data.serialize());
|
state::send_message(users, guild, data.serialize());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user