Skip to content

Commit 3756374

Browse files
Merge pull request #20481 from kamil-tekiela/getPartitions
Refactor getPartitions()
2 parents 41ea8d1 + da3670b commit 3756374

3 files changed

Lines changed: 25 additions & 24 deletions

File tree

‎phpstan-baseline.neon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8088,7 +8088,7 @@ parameters:
80888088
-
80898089
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
80908090
identifier: empty.notAllowed
8091-
count: 3
8091+
count: 2
80928092
path: src/Partitioning/Partition.php
80938093

80948094
-

‎psalm-baseline.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5251,7 +5251,6 @@
52515251
</PossiblyUnusedMethod>
52525252
<RiskyTruthyFalsyComparison>
52535253
<code><![CDATA[$dbi->fetchValue('SELECT @@have_partitioning;')]]></code>
5254-
<code><![CDATA[empty($row['PARTITION_NAME'])]]></code>
52555254
<code><![CDATA[empty($row['SUBPARTITION_NAME'])]]></code>
52565255
</RiskyTruthyFalsyComparison>
52575256
</file>

‎src/Partitioning/Partition.php‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,37 @@ public function getSubPartitions(): array
141141
*/
142142
public static function getPartitions(string $db, string $table): array
143143
{
144-
if (self::havePartitioning()) {
145-
$dbi = DatabaseInterface::getInstance();
146-
$result = $dbi->fetchResultSimple(
147-
'SELECT * FROM `information_schema`.`PARTITIONS`'
148-
. ' WHERE `TABLE_SCHEMA` = ' . $dbi->quoteString($db)
149-
. ' AND `TABLE_NAME` = ' . $dbi->quoteString($table),
150-
);
151-
if ($result !== []) {
152-
$partitionMap = [];
153-
foreach ($result as $row) {
154-
if (empty($row['PARTITION_NAME'])) {
155-
continue;
156-
}
144+
if (! self::havePartitioning()) {
145+
return [];
146+
}
157147

158-
$partition = $partitionMap[$row['PARTITION_NAME']] ?? new Partition($row);
159-
$partitionMap[$row['PARTITION_NAME']] = $partition;
148+
$dbi = DatabaseInterface::getInstance();
149+
$result = $dbi->fetchResultSimple(
150+
'SELECT * FROM `information_schema`.`PARTITIONS`'
151+
. ' WHERE `TABLE_SCHEMA` = ' . $dbi->quoteString($db)
152+
. ' AND `TABLE_NAME` = ' . $dbi->quoteString($table),
153+
);
154+
if ($result === []) {
155+
return [];
156+
}
160157

161-
if (empty($row['SUBPARTITION_NAME'])) {
162-
continue;
163-
}
158+
$partitionMap = [];
159+
foreach ($result as $row) {
160+
$partitionName = $row['PARTITION_NAME'] ?? '';
161+
if ($partitionName === '') {
162+
continue;
163+
}
164164

165-
$partition->addSubPartition(new SubPartition($row));
166-
}
165+
$partitionMap[$partitionName] ??= new Partition($row);
167166

168-
return array_values($partitionMap);
167+
if (empty($row['SUBPARTITION_NAME'])) {
168+
continue;
169169
}
170+
171+
$partitionMap[$partitionName]->addSubPartition(new SubPartition($row));
170172
}
171173

172-
return [];
174+
return array_values($partitionMap);
173175
}
174176

175177
/**

0 commit comments

Comments
 (0)