From 34d3e47b2d439bc36661e309468850bc166f6854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Thu, 29 May 2025 01:50:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=88=97=E8=A1=A8/=E8=A7=86=E9=A2=91=E5=90=88?= =?UTF-8?q?=E9=9B=86=E7=9A=84=E6=89=AB=E6=8F=8F=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD=20(#342)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/bili_sync/src/adapter/collection.rs | 16 +++++++++++++++- crates/bili_sync/src/adapter/mod.rs | 9 +++++++++ crates/bili_sync/src/workflow.rs | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/bili_sync/src/adapter/collection.rs b/crates/bili_sync/src/adapter/collection.rs index dbbabae..f63241a 100644 --- a/crates/bili_sync/src/adapter/collection.rs +++ b/crates/bili_sync/src/adapter/collection.rs @@ -44,13 +44,27 @@ impl VideoSource for collection::Model { true } + fn should_filter( + &self, + video_info: Result, + latest_row_at: &chrono::DateTime, + ) -> Option { + // 由于 collection 的视频无固定时间顺序,should_take 无法提前中断拉取,因此 should_filter 环节需要进行额外过滤 + if let Ok(video_info) = video_info { + if video_info.release_datetime() > latest_row_at { + return Some(video_info); + } + } + None + } + fn log_refresh_video_start(&self) { info!("开始扫描{}「{}」..", CollectionType::from(self.r#type), self.name); } fn log_refresh_video_end(&self, count: usize) { info!( - "扫描{}「{}」完成,已拉取 {} 条视频", + "扫描{}「{}」完成,获取到 {} 条新视频", CollectionType::from(self.r#type), self.name, count, diff --git a/crates/bili_sync/src/adapter/mod.rs b/crates/bili_sync/src/adapter/mod.rs index 0178128..84edcdd 100644 --- a/crates/bili_sync/src/adapter/mod.rs +++ b/crates/bili_sync/src/adapter/mod.rs @@ -58,6 +58,15 @@ pub trait VideoSource { release_datetime > latest_row_at } + fn should_filter( + &self, + video_info: Result, + _latest_row_at: &chrono::DateTime, + ) -> Option { + // 视频按照时间顺序拉取,should_take 已经获取了所有需要处理的视频,should_filter 无需额外处理 + video_info.ok() + } + /// 开始刷新视频 fn log_refresh_video_start(&self); diff --git a/crates/bili_sync/src/workflow.rs b/crates/bili_sync/src/workflow.rs index 2d6a75e..84a1823 100644 --- a/crates/bili_sync/src/workflow.rs +++ b/crates/bili_sync/src/workflow.rs @@ -76,7 +76,7 @@ pub async fn refresh_video_source<'a>( } } }) - .filter_map(|res| futures::future::ready(res.ok())) + .filter_map(|res| futures::future::ready(video_source.should_filter(res, &latest_row_at))) .chunks(10); let mut count = 0; while let Some(videos_info) = video_streams.next().await {