Skip to content

Commit 547e62b

Browse files
Attempt multiple global handles
1 parent 5dc53a2 commit 547e62b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ludicrousdb/includes/sharding.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
final class MultisiteDataset_Config {
1111
const GLOBAL_DATASET = 'global';
1212
const GLOBAL_READER = 'global__r';
13+
const GLOBAL_WRITER = 'global__w';
1314
const DATASET_FIELD = 'dataset';
1415
}
1516

@@ -252,8 +253,17 @@ public function unset_dataset( int $bid ) {
252253
* @param LudicrousDB $wpdb LudicrousDB instance
253254
*/
254255
public function shard_update( $blog_id, $shard, $wpdb ): bool {
255-
$global = MultisiteDataset_Config::GLOBAL_READER;
256-
$dbh = $wpdb->dbhs[ $global ];
256+
$handles = array(
257+
MultisiteDataset_Config::GLOBAL_WRITER,
258+
MultisiteDataset_Config::GLOBAL_READER,
259+
);
260+
$dbh = false;
261+
foreach ( $handles as $global ) {
262+
$dbh = $wpdb->dbhs[ $global ];
263+
if ( ! empty( $dbh ) ) {
264+
break;
265+
}
266+
}
257267
if ( empty( $dbh ) ) {
258268
return false; // should be unreachable, yet...
259269
}

0 commit comments

Comments
 (0)