mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-04 23:18:02 +08:00
fix: 修复视频 page 过多时数据库插入失败的问题 (#162)
This commit is contained in:
@@ -6,7 +6,7 @@ use bili_sync_entity::*;
|
|||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
use sea_orm::sea_query::{OnConflict, SimpleExpr};
|
||||||
use sea_orm::ActiveValue::Set;
|
use sea_orm::ActiveValue::Set;
|
||||||
use sea_orm::{Condition, QuerySelect};
|
use sea_orm::{Condition, DatabaseTransaction, QuerySelect};
|
||||||
|
|
||||||
use crate::bilibili::{BiliError, PageInfo, VideoInfo};
|
use crate::bilibili::{BiliError, PageInfo, VideoInfo};
|
||||||
use crate::config::TEMPLATE;
|
use crate::config::TEMPLATE;
|
||||||
@@ -99,7 +99,7 @@ pub(super) async fn error_fetch_video_detail(
|
|||||||
pub(crate) async fn create_video_pages(
|
pub(crate) async fn create_video_pages(
|
||||||
pages_info: &[PageInfo],
|
pages_info: &[PageInfo],
|
||||||
video_model: &video::Model,
|
video_model: &video::Model,
|
||||||
connection: &impl ConnectionTrait,
|
connection: &DatabaseTransaction,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let page_models = pages_info
|
let page_models = pages_info
|
||||||
.iter()
|
.iter()
|
||||||
@@ -128,14 +128,16 @@ pub(crate) async fn create_video_pages(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<page::ActiveModel>>();
|
.collect::<Vec<page::ActiveModel>>();
|
||||||
page::Entity::insert_many(page_models)
|
for page_chunk in page_models.chunks(50) {
|
||||||
.on_conflict(
|
page::Entity::insert_many(page_chunk.to_vec())
|
||||||
OnConflict::columns([page::Column::VideoId, page::Column::Pid])
|
.on_conflict(
|
||||||
.do_nothing()
|
OnConflict::columns([page::Column::VideoId, page::Column::Pid])
|
||||||
.to_owned(),
|
.do_nothing()
|
||||||
)
|
.to_owned(),
|
||||||
.do_nothing()
|
)
|
||||||
.exec(connection)
|
.do_nothing()
|
||||||
.await?;
|
.exec(connection)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user