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/tests/testcases/core/class-bp-core-user.php

    r7425 r7860  
    33/**
    44 * @group core
     5 * @group BP_Core_User
    56 */
    67class BP_Tests_BP_Core_User_TestCases extends BP_UnitTestCase {
     
    120121    }
    121122
     123    /**
     124     * @group last_activity
     125     */
     126    public function test_get_last_activity() {
     127        $u = $this->create_user();
     128        $time = bp_core_current_time();
    122129
     130        BP_Core_User::update_last_activity( $u, $time );
    123131
     132        $a = BP_Core_User::get_last_activity( $u );
     133        $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
     134
     135        $this->assertEquals( $time, $found );
     136    }
     137
     138    /**
     139     * @group last_activity
     140     */
     141    public function test_update_last_activity() {
     142        $u = $this->create_user();
     143        $time = bp_core_current_time();
     144        $time2 = '1968-12-25 01:23:45';
     145
     146        BP_Core_User::update_last_activity( $u, $time );
     147        $a = BP_Core_User::get_last_activity( $u );
     148        $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
     149        $this->assertEquals( $time, $found );
     150
     151        BP_Core_User::update_last_activity( $u, $time2 );
     152        $a = BP_Core_User::get_last_activity( $u );
     153        $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
     154        $this->assertEquals( $time2, $found );
     155    }
     156
     157    /**
     158     * @group last_activity
     159     */
     160    public function test_delete_last_activity() {
     161        $u = $this->create_user();
     162        $time = bp_core_current_time();
     163
     164        BP_Core_User::update_last_activity( $u, $time );
     165        $a = BP_Core_User::get_last_activity( $u );
     166        $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
     167        $this->assertEquals( $time, $found );
     168
     169        BP_Core_User::delete_last_activity( $u );
     170        $a = BP_Core_User::get_last_activity( $u );
     171        $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
     172        $this->assertEquals( '', $found );
     173    }
    124174}
Note: See TracChangeset for help on using the changeset viewer.