Skip to content

Commit

Permalink
Merge pull request #10 from fredden/performance/query-outside-loop
Browse files Browse the repository at this point in the history
Move null value check outside loop
  • Loading branch information
peterjaap authored Mar 11, 2022
2 parents f7c3d75 + e8c1e84 commit 19047da
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions Console/Command/RestoreUseDefaultValueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,18 @@ public function execute(InputInterface $input, OutputInterface $output)
$counts[$row['attribute_id']]++;
}
}
}

$nullValues = $db->fetchOne(
'SELECT COUNT(*) FROM ' . $fullTableName
. ' WHERE store_id = ? AND value IS NULL',
[$row['store_id']]
);
$nullValues = $db->fetchOne(
'SELECT COUNT(*) FROM ' . $fullTableName . ' WHERE store_id != 0 AND value IS NULL'
);

if (!$isDryRun && $nullValues > 0) {
$output->writeln("Deleting " . $nullValues . " NULL value(s) from " . $fullTableName);
// Remove all non-global null values
$db->query(
'DELETE FROM ' . $fullTableName
. ' WHERE store_id = ? AND value IS NULL',
[$row['store_id']]
);
}
if (!$isDryRun && $nullValues > 0) {
$output->writeln("Deleting " . $nullValues . " NULL value(s) from " . $fullTableName);
// Remove all non-global null values
$db->query(
'DELETE FROM ' . $fullTableName . ' WHERE store_id != 0 AND value IS NULL'
);
}

if (count($counts)) {
Expand Down

0 comments on commit 19047da

Please sign in to comment.