Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/12/2014 09:27:20 PM (10 years ago)
Author:
boonebgorges
Message:

Migrate user 'last_activity' data from usermeta to the activity table

Storing last_activity in usermeta caused severe bottlenecks on sites with
large user bases. The usermeta table has a tendency to get bloated. Its
option_value column is not indexed, and even if it were, it would not be
indexed properly for the kind of chronological sorting that BuddyPress was
using it for.

This changeset refactors all core last_activity user functionality, so that
the data is stored in the wp_bp_activity table (even when the activity
component is disabled).

For backward compatibility with plugins that reference last_activity metadata
entries, all last_activity data is retained in wp_usermeta, and new data will
be mirrored there until further notice.

See #5128

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-update.php

    r7798 r7860  
    230230        if ( $raw_db_version < 7731 ) {
    231231            bp_update_to_1_9_2();
     232        }
     233
     234        // 2.0
     235        if ( $raw_db_version < 7859 ) {
     236            bp_update_to_2_0();
    232237        }
    233238    }
     
    329334
    330335/**
     336 * 2.0 update routine.
     337 *
     338 * - Ensure that the activity tables are installed, for last_activity storage.
     339 * - Migrate last_activity data from usermeta to activity table
     340 */
     341function bp_update_to_2_0() {
     342    global $wpdb;
     343
     344    // Install activity tables
     345    bp_core_install_activity_streams();
     346
     347    $bp = buddypress();
     348
     349    // Migrate data
     350    // The "NOT IN" clause prevents duplicates
     351    $sql = "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `date_recorded` ) (
     352          SELECT user_id, '{$bp->members->id}' as component, 'last_activity' as type, meta_value AS date_recorded
     353          FROM {$wpdb->usermeta}
     354          WHERE
     355            meta_key = 'last_activity'
     356            AND
     357            user_id NOT IN (
     358              SELECT user_id
     359              FROM {$bp->members->table_name_last_activity}
     360              WHERE component = '{$bp->members->id}' AND type = 'last_activity'
     361            )
     362    );";
     363
     364    $wpdb->query( $sql );
     365}
     366
     367/**
    331368 * Redirect user to BP's What's New page on first page load after activation.
    332369 *
Note: See TracChangeset for help on using the changeset viewer.