Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/30/2014 07:22:59 PM (10 years ago)
Author:
boonebgorges
Message:

When migrating last_activity data, clear all data to avoid duplicates

Previously, duplicates were avoided with a NOT IN subquery. But this caused
load problems on large installations, where the subquery would return
many thousands of results.

Fixes #5572

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/members/functions.php

    r8330 r8333  
    354354        $this->assertSame( $u_obj->user_email, $found_email );
    355355    }
     356
     357    /**
     358     * @group bp_last_activity_migrate
     359     * @expectedIncorrectUsage update_user_meta( $user_id, 'last_activity' )
     360     * @expectedIncorrectUsage get_user_meta( $user_id, 'last_activity' )
     361     */
     362    public function test_bp_last_activity_migrate() {
     363        // We explicitly do not want last_activity created, so use the
     364        // WP factory methods
     365        $u1 = $this->factory->user->create();
     366        $u2 = $this->factory->user->create();
     367        $u3 = $this->factory->user->create();
     368
     369        $time = time();
     370        $t1 = date( 'Y-m-d H:i:s', $time - 50 );
     371        $t2 = date( 'Y-m-d H:i:s', $time - 500 );
     372        $t3 = date( 'Y-m-d H:i:s', $time - 5000 );
     373
     374        update_user_meta( $u1, 'last_activity', $t1 );
     375        update_user_meta( $u2, 'last_activity', $t2 );
     376        update_user_meta( $u3, 'last_activity', $t3 );
     377
     378        // Create an existing entry in last_activity to test no dupes
     379        global $wpdb, $bp;
     380        $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) VALUES ( %d, %s, %s, %s, %s, %s, %d, %s )", $u2, $bp->members->id, 'last_activity', '', '', 0, $t1 ) );
     381
     382        bp_last_activity_migrate();
     383
     384        $expected = array(
     385            $u1 => $t1,
     386            $u2 => $t2,
     387            $u3 => $t3,
     388        );
     389
     390        $found = array(
     391            $u1 => '',
     392            $u2 => '',
     393            $u3 => '',
     394        );
     395
     396        foreach ( $found as $uid => $v ) {
     397            $found[ $uid ] = bp_get_user_last_activity( $uid );
     398        }
     399
     400        $this->assertSame( $expected, $found );
     401    }
    356402}
Note: See TracChangeset for help on using the changeset viewer.