Skip to content

Commit

Permalink
Fix batch size to work with SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
Turner committed Jun 11, 2022
1 parent edd5a4b commit 7bebda6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions indexer/tasks/src/genesis/genesis_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fn add_non_avvms(
}
}

// https://github.com/SeaQL/sea-orm/issues/691
async fn insert_active_models<ActiveModel>(
db_tx: &DatabaseTransaction,
active_models: Vec<ActiveModel>,
Expand All @@ -197,9 +198,10 @@ where
ActiveModel: ActiveModelTrait + ActiveModelBehavior + Send + Sync,
<<ActiveModel as ActiveModelTrait>::Entity as EntityTrait>::Model: IntoActiveModel<ActiveModel>,
{
let batch_size = u16::MAX
/ <<ActiveModel as ActiveModelTrait>::Entity as EntityTrait>::Column::iter().count() as u16;
for chunk in active_models.chunks(batch_size as usize) {
// Max parameter count for SQLite: https://www.sqlite.org/limits.html
let batch_size = 32766usize
/ <<ActiveModel as ActiveModelTrait>::Entity as EntityTrait>::Column::iter().count();
for chunk in active_models.chunks(batch_size) {
ActiveModel::Entity::insert_many(chunk.to_vec())
.exec(db_tx)
.await?;
Expand Down

0 comments on commit 7bebda6

Please sign in to comment.