fix: 为填充视频详情添加并发限制,避免数据库竞争 (#419)
This commit is contained in:
@@ -102,10 +102,13 @@ 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?;
|
||||||
|
let semaphore = Semaphore::new(VersionedConfig::get().load().concurrent_limit.video);
|
||||||
|
let semaphore_ref = &semaphore;
|
||||||
let tasks = videos_model
|
let tasks = videos_model
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|video_model| {
|
.map(|video_model| {
|
||||||
async move {
|
async move {
|
||||||
|
let _permit = semaphore_ref.acquire().await.context("acquire semaphore failed")?;
|
||||||
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user