Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/19/2009 01:35:32 PM (17 years ago)
Author:
apeatling
Message:

Added basic object caching support ready for the first release. This will cut the number of database calls and load by 3x. Add define( 'WP_CACHE', true ); to you wp-config.php and drop object-cache.php into /wp-content/ to enable.

A good file based object cache is available here:
http://neosmart.net/dl.php?id=14

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-templatetags.php

    r1221 r1238  
    152152       
    153153        // If this is a single group then instantiate group meta when creating the object.
    154         if ( $this->single_group )
    155             $this->group = new BP_Groups_Group( $this->group->group_id, true );
    156         else
    157             $this->group = new BP_Groups_Group( $this->group->group_id, false, false );
    158 
     154        if ( $this->single_group ) {
     155            if ( !$group = wp_cache_get( 'groups_group_' . $this->group->group_id, 'bp' ) ) {
     156                $group = new BP_Groups_Group( $this->group->group_id, true );
     157                wp_cache_set( 'groups_group_' . $this->group->group_id, $group, 'bp' );
     158            }
     159        } else {
     160            if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $this->group->group_id, 'bp' ) ) {
     161                $group = new BP_Groups_Group( $this->group->group_id, false, false );
     162                wp_cache_set( 'groups_group_nouserdata_' . $this->group->group_id, $group, 'bp' );
     163            }
     164        }
     165       
     166        $this->group = $group;
     167       
    159168        if ( 0 == $this->current_group ) // loop has just started
    160169            do_action('loop_start');
     
    984993       
    985994        <ul id="friend-list" class="item-list">
    986             <?php for( $i = 0; $i < count($invites); $i++ ) {
    987                 $user = new BP_Core_User( $invites[$i] ); ?>
    988    
     995            <?php for ( $i = 0; $i < count($invites); $i++ ) {
     996                if ( !$user = wp_cache_get( 'bp_user_' . $invites[$i], 'bp' ) ) {
     997                    $user = new BP_Core_User( $invites[$i] );
     998                    wp_cache_set( 'bp_user_' . $invites[$i], $user, 'bp' );
     999                }
     1000                ?>
    9891001                <li id="uid-<?php echo $user->id ?>">
    9901002                    <?php echo $user->avatar_thumb ?>
     
    13561368    global $bp;
    13571369   
    1358     $group_ids = BP_Groups_Group::get_random( $total_groups, 1 );
     1370    if ( !$group_ids = wp_cache_get( 'groups_random_groups', 'bp' ) ) {
     1371        $group_ids = BP_Groups_Group::get_random( $total_groups, 1 );
     1372        wp_cache_set( 'groups_random_groups', $group_ids, 'bp' );
     1373    }
    13591374?> 
    13601375    <?php if ( $group_ids['groups'] ) { ?>
    13611376        <ul class="item-list" id="random-groups-list">
    1362         <?php for ( $i = 0; $i < count( $group_ids['groups'] ); $i++ ) { ?>
    1363             <?php $group = new BP_Groups_Group( $group_ids['groups'][$i]->group_id, false, false ); ?>
     1377        <?php
     1378            for ( $i = 0; $i < count( $group_ids['groups'] ); $i++ ) {
     1379                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_ids['groups'][$i]->group_id, 'bp' ) ) {
     1380                    $group = new BP_Groups_Group( $group_ids['groups'][$i]->group_id, false, false );
     1381                    wp_cache_set( 'groups_group_nouserdata_' . $group_ids['groups'][$i]->group_id, $group, 'bp' );
     1382                }
     1383            ?> 
    13641384            <li>
    13651385                <div class="item-avatar">
     
    14011421    global $bp;
    14021422   
    1403     $group_ids = groups_get_random_groups_for_user( $bp->displayed_user->id, $total_groups, 1 );
     1423    if ( !$group_ids = wp_cache_get( 'groups_random_user_groups_' . $bp->displayed_user->id . '_' . $total_groups, 'bp' ) ) {
     1424        $group_ids = groups_get_random_groups_for_user( $bp->displayed_user->id, $total_groups, 1 );
     1425        wp_cache_set( 'groups_random_user_groups_' . $bp->displayed_user->id . '_' . $total_groups, $group_ids, 'bp' );
     1426    }
     1427   
    14041428?> 
    14051429    <div class="info-group">
     
    14071431        <?php if ( $group_ids ) { ?>
    14081432            <ul class="horiz-gallery">
    1409             <?php for ( $i = 0; $i < count( $group_ids ); $i++ ) { ?>
    1410                 <?php $group = new BP_Groups_Group( $group_ids[$i], false, false ); ?>
    1411                 <li>
     1433            <?php
     1434            for ( $i = 0; $i < count( $group_ids ); $i++ ) {
     1435                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_ids[$i], 'bp' ) ) {
     1436                    $group = new BP_Groups_Group( $group_ids[$i], false, false );
     1437                    wp_cache_set( 'groups_group_nouserdata_' . $group_ids[$i], $group, 'bp' );
     1438                }
     1439            ?>              <li>
    14121440                    <a href="<?php echo bp_group_permalink( $group, false ) ?>"><img src="<?php echo $group->avatar_thumb; ?>" class="avatar" alt="<?php _e( 'Group Avatar', 'buddypress' ) ?>" /></a>
    14131441                    <h5><a href="<?php echo bp_group_permalink( $group, false ) ?>"><?php echo $group->name ?></a></h5>
Note: See TracChangeset for help on using the changeset viewer.