meme cache now refreshed after response has been sent
continuous-integration/drone/push Build is failing Details

This commit is contained in:
LordMZTE 2021-06-22 14:01:33 +02:00
parent d8a846a8cb
commit 48d479973b
4 changed files with 20 additions and 10 deletions

View File

@ -7,6 +7,14 @@ steps:
- apt update
- apt install -y cmake
- cargo test -v
- name: clippy-linux
image: rust
commands:
- apt update
- apt install -y cmake
- cargo clippy
---
kind: pipeline
name: release

View File

@ -1,5 +1,2 @@
# 0.2.1
- added video support
- added `jens` command
- added `party` command
- meme cache now stores data encoded with bincode. **DELETE BEFORE UPDATE**
# 0.2.2
- meme cache is now updated after reponse has been sent to reduce latency

View File

@ -1,6 +1,6 @@
[package]
name = "ruff"
version = "0.2.1"
version = "0.2.2"
authors = ["LordMZTE <lord@mzte.de>"]
edition = "2018"

View File

@ -69,10 +69,6 @@ pub async fn on_msg(msg: &str, room: Room, bot: &Bot) -> anyhow::Result<()> {
for meme in &bot.config.memes {
if meme.matches(msg) {
bot.meme_count.fetch_add(1, Ordering::SeqCst);
if bot.meme_count.load(Ordering::SeqCst) >= bot.config.clear_cache_threshold {
bot.jm_client.write().await.clear_cache().await;
bot.meme_count.store(0, Ordering::SeqCst);
}
let meme_name = &meme.keyword;
if let Some(meme) = meme.get_meme(bot).await? {
@ -129,6 +125,15 @@ pub async fn on_msg(msg: &str, room: Room, bot: &Bot) -> anyhow::Result<()> {
error!("Found meme with invalid id! {:?}", &meme);
}
}
// we do this after we have responded, in order to not delay the response
if bot.meme_count.load(Ordering::SeqCst) >= bot.config.clear_cache_threshold {
let mut client = bot.jm_client.write().await;
bot.meme_count.store(0, Ordering::SeqCst);
client.clear_cache().await;
// memes requested but not used, but they will be cached
client.get_memes().await?;
}
}
Ok(())