Skip to content

Commit 19047da

Browse files
authored
Merge pull request #10 from fredden/performance/query-outside-loop
Move null value check outside loop
2 parents f7c3d75 + e8c1e84 commit 19047da

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

Console/Command/RestoreUseDefaultValueCommand.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,18 @@ public function execute(InputInterface $input, OutputInterface $output)
107107
$counts[$row['attribute_id']]++;
108108
}
109109
}
110+
}
110111

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

117-
if (!$isDryRun && $nullValues > 0) {
118-
$output->writeln("Deleting " . $nullValues . " NULL value(s) from " . $fullTableName);
119-
// Remove all non-global null values
120-
$db->query(
121-
'DELETE FROM ' . $fullTableName
122-
. ' WHERE store_id = ? AND value IS NULL',
123-
[$row['store_id']]
124-
);
125-
}
116+
if (!$isDryRun && $nullValues > 0) {
117+
$output->writeln("Deleting " . $nullValues . " NULL value(s) from " . $fullTableName);
118+
// Remove all non-global null values
119+
$db->query(
120+
'DELETE FROM ' . $fullTableName . ' WHERE store_id != 0 AND value IS NULL'
121+
);
126122
}
127123

128124
if (count($counts)) {

0 commit comments

Comments
 (0)