Skip to content

Commit

Permalink
Chunk inserts to avoid variable binding limit on large DBs
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Dec 18, 2024
1 parent abbdf4e commit 59e80cc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions classes/migration/upgrade/v3_5_0/I9771_OrcidMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ private function movePluginSettings(): void
]);
});

DB::table($this->settingsTableName)
->insert($mappedResults->toArray());
// Insert max 100 results at a time
foreach ($mappedResults->chunk(16000) as $mappedResultsChunk) {
DB::table($this->settingsTableName)
->insert($mappedResultsChunk->toArray());
}

DB::table('plugin_settings')
->where('plugin_name', '=', 'orcidprofileplugin')
Expand Down Expand Up @@ -200,12 +203,15 @@ private function markVerifiedOrcids(): void
$tableInfo['id'] => $key,
'setting_name' => 'orcidIsVerified',
'setting_value' => true,
'locale' => '',
];
});

if ($insertValues->isNotEmpty()) {
DB::table($tableInfo['name'])
->insert($insertValues->toArray());
foreach ($insertValues->chunk(16000) as $chunkedInsertValues) {
DB::table($tableInfo['name'])
->insert($chunkedInsertValues->toArray());
}
}
}
}
Expand Down

0 comments on commit 59e80cc

Please sign in to comment.