mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 23:49:53 +08:00
refactor: 优化填充视频详情时的性能 (#350)
This commit is contained in:
@@ -103,7 +103,10 @@ pub async fn fetch_video_details(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
video_source.log_fetch_video_start();
|
video_source.log_fetch_video_start();
|
||||||
let videos_model = filter_unfilled_videos(video_source.filter_expr(), connection).await?;
|
let videos_model = filter_unfilled_videos(video_source.filter_expr(), connection).await?;
|
||||||
for video_model in videos_model {
|
let tasks = videos_model
|
||||||
|
.into_iter()
|
||||||
|
.map(|video_model| {
|
||||||
|
async move {
|
||||||
let video = Video::new(bili_client, video_model.bvid.clone());
|
let video = Video::new(bili_client, video_model.bvid.clone());
|
||||||
let info: Result<_> = async { Ok((video.get_tags().await?, video.get_view_info().await?)) }.await;
|
let info: Result<_> = async { Ok((video.get_tags().await?, video.get_view_info().await?)) }.await;
|
||||||
match info {
|
match info {
|
||||||
@@ -135,7 +138,11 @@ pub async fn fetch_video_details(
|
|||||||
txn.commit().await?;
|
txn.commit().await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Ok::<_, anyhow::Error>(())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.collect::<FuturesUnordered<_>>();
|
||||||
|
tasks.try_collect::<Vec<_>>().await?;
|
||||||
video_source.log_fetch_video_end();
|
video_source.log_fetch_video_end();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user