Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/19/2009 01:35:32 PM (16 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-ajax.php

    r1221 r1238  
    5959    switch ( $_POST['filter'] ) {
    6060        case 'newest-groups':
    61             $groups = groups_get_newest( $_POST['max-groups'], 1 );
     61            if ( !$groups = wp_cache_get( 'newest_groups', 'bp' ) ) {
     62                $groups = groups_get_newest( $_POST['max-groups'], 1 );
     63                wp_cache_set( 'newest_groups', $groups, 'bp' );
     64            }
    6265        break;
    6366        case 'recently-active-groups':
    64             $groups = groups_get_active( $_POST['max-groups'], 1 );
     67            if ( !$groups = wp_cache_get( 'active_groups', 'bp' ) ) {
     68                $groups = groups_get_active( $_POST['max-groups'], 1 );
     69                wp_cache_set( 'active_groups', $groups, 'bp' );
     70            }
    6571        break;
    6672        case 'popular-groups':
    67             $groups = groups_get_popular( $_POST['max-groups'], 1 );
     73            if ( !$groups = wp_cache_get( 'popular_groups', 'bp' ) ) {
     74                $groups = groups_get_popular( $_POST['max-groups'], 1 );
     75                wp_cache_set( 'popular_groups', $groups, 'bp' );
     76            }
    6877        break;
    6978    }
     
    7281        echo '0[[SPLIT]]'; // return valid result.
    7382   
    74         foreach ( (array) $groups['groups'] as $group ) {
    75             $group = new BP_Groups_Group( $group->group_id, false, false );
     83        foreach ( (array) $groups['groups'] as $group_id ) {
     84            if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     85                $group = new BP_Groups_Group( $group_id->group_id, false, false );
     86                wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     87            }   
    7688        ?>
    7789            <li>
     
    240252        <?php $counter = 0; ?>
    241253        <ul id="groups-list" class="item-list">
    242         <?php foreach ( $groups['groups'] as $group ) : ?>
     254        <?php foreach ( $groups['groups'] as $group_id ) : ?>
    243255           
    244256            <?php $alt = ( $counter % 2 == 1 ) ? ' class="alt"' : ''; ?>
    245             <?php $group = new BP_Groups_Group( $group->group_id, false, false ); ?>
     257            <?php
     258                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     259                    $group = new BP_Groups_Group( $group_id->group_id, false, false );
     260                    wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     261                }   
     262            ?>
    246263           
    247264            <li<?php echo $alt ?>>
Note: See TracChangeset for help on using the changeset viewer.