Skip to content
Snippets Groups Projects

imp: post_update performance

Merged simon requested to merge imp-post-update-performance into master
Compare and
1 file
+ 22
15
Preferences
File browser
Compare changes
@@ -119,11 +119,15 @@ function shareholder_register_post_update_indexes(&$sandbox) {
* Update current holder for shares.
*/
function shareholder_register_post_update_current_holder(&$sandbox) {
$share_ids = \Drupal::entityQuery('share')->execute();
foreach (array_chunk($share_ids, 250) as $current_share_ids_chunk) {
foreach (Share::loadMultiple($current_share_ids_chunk) as $share) {
$share->save();
}
\Drupal::database()->query(
"update {share} " .
"inner join {share__share_transaction_ids} on {share}.id = {share__share_transaction_ids}.entity_id " .
"inner join {share_transaction} on share_transaction_ids_target_id = {share_transaction}.id " .
"set {share}.shareholder_id = {share_transaction}.shareholder_id ".
"where {share_transaction}.state = 'valid' and {share}.state in ('issued', 'redeemed');"
);
foreach (\Drupal::database()->query("select entity_id from share__share_transaction_ids group by entity_id having count(*) > 1") as $row) {
Share::load($row->entity_id)->save();
}
}
@@ -131,16 +135,19 @@ function shareholder_register_post_update_current_holder(&$sandbox) {
* Update share issue for shares.
*/
function shareholder_register_post_update_share_issue(&$sandbox) {
$share_ids = \Drupal::entityQuery('share')
->condition('state', ['issued', 'redeemed'], 'IN')
->execute();
foreach (array_chunk($share_ids, 250) as $current_share_ids_chunk) {
foreach (Share::loadMultiple($current_share_ids_chunk) as $share) {
$share->set(
'share_issue_id',
$share->getIssuingTransaction()->getShareIssue()->id()
)->save();
}
\Drupal::database()->query(
"update {share} " .
"inner join {share__share_transaction_ids} on {share}.id = {share__share_transaction_ids}.entity_id " .
"inner join {share_transaction} on share_transaction_ids_target_id = {share_transaction}.id " .
"set {share}.share_issue_id = {share_transaction}.share_issue_id ".
"where {share_transaction}.state = 'valid' and {share}.state in ('issued', 'redeemed');"
);
foreach (\Drupal::database()->query("select entity_id from share__share_transaction_ids group by entity_id having count(*) > 1") as $row) {
$share = Share::load($row->entity_id);
$share->set(
'share_issue_id',
$share->getIssuingTransaction()->getShareIssue()->id()
)->save();
}
}