Skip to content

Commit

Permalink
Merge pull request #1989 from ravinderk/performance
Browse files Browse the repository at this point in the history
Performance
  • Loading branch information
Devin Walker committed Aug 15, 2017
2 parents 7366d2c + 0d38906 commit 42327ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
46 changes: 34 additions & 12 deletions includes/class-give-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function get( $row_id ) {
/* @var WPDB $wpdb */
global $wpdb;

// Bailout.
if ( empty( $row_id ) ) {
return null;
}

return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
}

Expand All @@ -111,16 +116,22 @@ public function get( $row_id ) {
* @since 1.0
* @access public
*
* @param int $column Column ID.
* @param int $row_id Row ID.
*
* @return object
* @param int $column Column ID.
* @param int $row_id Row ID.
*
* @return object
*/
public function get_by( $column, $row_id ) {
/* @var WPDB $wpdb */
global $wpdb;
/* @var WPDB $wpdb */
global $wpdb;

// Bailout.
if ( empty( $column ) || empty( $row_id ) ) {
return null;
}

$column = esc_sql( $column );

return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );
}

Expand All @@ -129,17 +140,23 @@ public function get_by( $column, $row_id ) {
*
* @since 1.0
* @access public
*
* @param int $column Column ID.
* @param int $row_id Row ID.
*
*
* @param int $column Column ID.
* @param int $row_id Row ID.
*
* @return string Column value.
*/
public function get_column( $column, $row_id ) {
/* @var WPDB $wpdb */
global $wpdb;
/* @var WPDB $wpdb */
global $wpdb;

// Bailout.
if ( empty( $column ) || empty( $row_id ) ) {
return null;
}

$column = esc_sql( $column );

return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
}

Expand All @@ -159,6 +176,11 @@ public function get_column_by( $column, $column_where, $column_value ) {
/* @var WPDB $wpdb */
global $wpdb;

// Bailout.
if ( empty( $column ) || empty( $column_where ) || empty( $column_value ) ) {
return null;
}

$column_where = esc_sql( $column_where );
$column = esc_sql( $column );
return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-give-donor.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Give_Donor {
*/
public function __construct( $_id_or_email = false, $by_user_id = false ) {

$this->db = new Give_DB_Donors();
$this->db = Give()->donors;

if (
false === $_id_or_email
Expand Down

0 comments on commit 42327ad

Please sign in to comment.