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

Performance #1989

Merged
merged 2 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
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
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