diff --git a/src/api/posts/trash.rs b/src/api/posts/trash.rs index 89679a2..60d44c8 100644 --- a/src/api/posts/trash.rs +++ b/src/api/posts/trash.rs @@ -218,6 +218,9 @@ pub async fn batch_restore_posts(post_ids: Vec) -> Result = Vec::with_capacity(post_ids.len() * 2); @@ -227,7 +230,7 @@ pub async fn batch_restore_posts(post_ids: Vec) -> Result) -> Result) -> Result = - affected_slugs.into_iter().collect(); - crate::cache::invalidate_post_lists(); - crate::cache::invalidate_all_tags(); - crate::cache::invalidate_post_stats(); - for slug in &unique_slugs { - crate::cache::invalidate_post_by_slug(slug).await; + if use_precise { + // 精准失效:先去重 slug,再统一失效列表/标签云/统计/标签文章。 + let unique_slugs: std::collections::HashSet = + affected_slugs.into_iter().collect(); + crate::cache::invalidate_post_lists(); + crate::cache::invalidate_all_tags(); + crate::cache::invalidate_post_stats(); + for slug in &unique_slugs { + crate::cache::invalidate_post_by_slug(slug).await; + } + crate::cache::invalidate_tag_posts_for(&affected_tags.into_iter().collect::>()).await; + } else { + // 影响集过大时回退到全量失效,避免大量串行缓存操作。 + crate::cache::invalidate_all_post_caches(); } - crate::cache::invalidate_tag_posts_for(&affected_tags.into_iter().collect::>()).await; Ok(CreatePostResponse { success: true,