Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup and fix for key with value 0 #125

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions ludicrousdb/includes/class-ludicrousdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/**
* LudicrousDB Class
*
* Disable this check for the file, since we explicitly overwrite default WP db behavior, so this error is always a false positive in this file
* phpcs:disable WordPress.DB.RestrictedFunctions
*
* @package Plugins/LudicrousDB/Class
*/

Expand Down Expand Up @@ -433,7 +436,7 @@ public function send_reads_to_masters() {
*/
public function run_callbacks( $group, $args = null ) {
if ( ! isset( $this->ludicrous_callbacks[ $group ] ) || ! is_array( $this->ludicrous_callbacks[ $group ] ) ) {
return null;
return;
}

if ( ! isset( $args ) ) {
Expand Down Expand Up @@ -599,8 +602,9 @@ public function db_connect( $query = '' ) {
$this->current_host = $this->dbh2host[ $dbhname ];

// Keep this connection at the top of the stack to prevent disconnecting frequently-used connections
if ( $k = array_search( $dbhname, $this->open_connections, true ) ) {
unset( $this->open_connections[ $k ] );
$key = array_search( $dbhname, $this->open_connections, true );
if ( $key !== false ) {
unset( $this->open_connections[ $key ] );
$this->open_connections[] = $dbhname;
}

Expand Down Expand Up @@ -650,7 +654,8 @@ public function db_connect( $query = '' ) {
}
}

if ( ! $tries_remaining = count( $servers ) ) {
$tries_remaining = count( $servers );
if ( $tries_remaining === 0 ) {
return $this->bail( "No database servers were found to match the query. ({$this->table}, {$dataset})" );
}

Expand Down Expand Up @@ -727,7 +732,7 @@ public function db_connect( $query = '' ) {
: $this->default_lag_threshold;

// Check for a lagged slave, if applicable
if ( empty( $use_master ) && empty( $write ) && empty ( $this->ignore_slave_lag ) && isset( $this->lag_threshold ) && ! isset( $server['host'] ) && ( $lagged_status = $this->get_lag_cache() ) === DB_LAG_BEHIND ) {
if ( empty( $use_master ) && empty( $write ) && empty( $this->ignore_slave_lag ) && isset( $this->lag_threshold ) && ! isset( $server['host'] ) && ( $lagged_status = $this->get_lag_cache() ) === DB_LAG_BEHIND ) {

// If it is the last lagged slave and it is with the best preference we will ignore its lag
if ( ! isset( $unique_lagged_slaves[ $host_and_port ] ) && $this->unique_servers == count( $unique_lagged_slaves ) + 1 && $group == $min_group ) {
Expand Down Expand Up @@ -1151,13 +1156,12 @@ public function set_charset( $dbh, $charset = null, $collate = null ) {
*
* @since 1.0.0
*
* @param string $dbhname Dataname key name.
* @param string $dbhname Database name.
*/
public function disconnect( $dbhname ) {

$k = array_search( $dbhname, $this->open_connections, true );
if ( ! empty( $k ) ) {
unset( $this->open_connections[ $k ] );
$key = array_search( $dbhname, $this->open_connections, true );
if ( $key !== false ) {
unset( $this->open_connections[ $key ] );
}

if ( $this->dbh_type_check( $this->dbhs[ $dbhname ] ) ) {
Expand Down Expand Up @@ -1746,7 +1750,7 @@ private function get_db_object( $dbh_or_table = false ) {
}

/**
* Check databse object type.
* Check database object type.
*
* @param resource|mysqli $dbh Database resource.
*
Expand Down