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 {