Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/29/2016 02:16:02 AM (7 years ago)
Author:
boonebgorges
Message:

XProfile: Add caching for fetching a field ID by name.

Fixes #7404.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r11316 r11352  
    918918        }
    919919
    920         $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s AND parent_id = 0", $field_name );
    921 
    922         $query = $wpdb->get_var( $sql );
    923 
    924         return is_numeric( $query ) ? (int) $query : $query;
     920        $id = bp_core_get_incremented_cache( $field_name, 'bp_xprofile_fields_by_name' );
     921        if ( false === $id ) {
     922            $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s AND parent_id = 0", $field_name );
     923            $id = $wpdb->get_var( $sql );
     924            bp_core_set_incremented_cache( $field_name, 'bp_xprofile_fields_by_name', $id );
     925        }
     926
     927        return is_numeric( $id ) ? (int) $id : $id;
    925928    }
    926929
Note: See TracChangeset for help on using the changeset viewer.