perf(cache): run tag post invalidations concurrently

This commit is contained in:
xfy 2026-06-17 16:59:29 +08:00
parent 2d8f1e0d98
commit 7bd02d0ea9
3 changed files with 8 additions and 3 deletions

1
Cargo.lock generated
View File

@ -5397,6 +5397,7 @@ dependencies = [
"deadpool-postgres", "deadpool-postgres",
"dioxus", "dioxus",
"dotenvy", "dotenvy",
"futures",
"governor", "governor",
"hex", "hex",
"http", "http",

View File

@ -36,6 +36,7 @@ zenwebp = { version = "0.3", optional = true }
moka = { version = "0.12", features = ["future"], optional = true } moka = { version = "0.12", features = ["future"], optional = true }
governor = { version = "0.8", optional = true } governor = { version = "0.8", optional = true }
md-5 = { version = "0.10", optional = true } md-5 = { version = "0.10", optional = true }
futures = { version = "0.3", optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Document", "Window", "Storage", "Element", "HtmlElement", "DomTokenList", "MediaQueryList", "HtmlImageElement", "MouseEvent", "KeyboardEvent", "Node", "EventTarget", "Navigator"] } web-sys = { version = "0.3", features = ["Document", "Window", "Storage", "Element", "HtmlElement", "DomTokenList", "MediaQueryList", "HtmlImageElement", "MouseEvent", "KeyboardEvent", "Node", "EventTarget", "Navigator"] }
@ -82,4 +83,5 @@ server = [
"dep:moka", "dep:moka",
"dep:governor", "dep:governor",
"dep:md-5", "dep:md-5",
"dep:futures",
] ]

View File

@ -291,9 +291,11 @@ pub fn invalidate_post_stats() {
/// 按标签批量失效文章列表缓存。 /// 按标签批量失效文章列表缓存。
#[cfg(feature = "server")] #[cfg(feature = "server")]
pub async fn invalidate_tag_posts_for(tags: &[String]) { pub async fn invalidate_tag_posts_for(tags: &[String]) {
for tag in tags { let futures: Vec<_> = tags
invalidate_posts_by_tag(tag).await; .iter()
} .map(|tag| invalidate_posts_by_tag(tag))
.collect();
let _ = futures::future::join_all(futures).await;
} }
/// 清空所有文章相关缓存(列表、标签、单篇、统计、标签文章)。 /// 清空所有文章相关缓存(列表、标签、单篇、统计、标签文章)。