refactor: 调整视频列表/视频合集的扫描逻辑,优化性能 (#342)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-05-29 01:50:06 +08:00
committed by GitHub
parent d7ec0584bc
commit 34d3e47b2d
3 changed files with 25 additions and 2 deletions

View File

@@ -44,13 +44,27 @@ impl VideoSource for collection::Model {
true
}
fn should_filter(
&self,
video_info: Result<VideoInfo, anyhow::Error>,
latest_row_at: &chrono::DateTime<Utc>,
) -> Option<VideoInfo> {
// 由于 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,

View File

@@ -58,6 +58,15 @@ pub trait VideoSource {
release_datetime > latest_row_at
}
fn should_filter(
&self,
video_info: Result<VideoInfo, anyhow::Error>,
_latest_row_at: &chrono::DateTime<Utc>,
) -> Option<VideoInfo> {
// 视频按照时间顺序拉取should_take 已经获取了所有需要处理的视频should_filter 无需额外处理
video_info.ok()
}
/// 开始刷新视频
fn log_refresh_video_start(&self);

View File

@@ -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 {