Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/20/2021 02:21:24 PM (2 years ago)
Author:
imath
Message:

Avoid generating many new_avatar activities in a short time frame

For an hour time frame, if a user publishes many new_avatar activities, only the latest one will be kept.

Props oztaser

See #8581

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/members/activity.php

    r12851 r13154  
    9494        $this->assertSame( $expected, $found );
    9595    }
     96
     97    /**
     98     * @group bp_members_new_avatar_activity
     99     */
     100    public function test_bp_members_new_avatar_activity_throttled() {
     101        $u = self::factory()->user->create();
     102        $a = self::factory()->activity->create( array(
     103            'component' => 'members',
     104            'type'      => 'new_avatar',
     105            'user_id'   => $u,
     106        ) );
     107
     108        bp_members_new_avatar_activity( $u );
     109
     110        $new_avatar_activities = bp_activity_get( array(
     111            'user_id'     => $u,
     112            'component'   => buddypress()->members->id,
     113            'type'        => 'new_avatar',
     114            'count_total' => 'count_query',
     115        ) );
     116
     117        $this->assertEquals( 1, $new_avatar_activities['total'] );
     118        $this->assertNotSame( $a, $new_avatar_activities['activities'][0]->id );
     119    }
     120
     121    /**
     122     * @group bp_members_new_avatar_activity
     123     */
     124    public function test_bp_members_new_avatar_activity_outside_of_throttle_time() {
     125        $u = self::factory()->user->create();
     126
     127        $time      = strtotime( bp_core_current_time() );
     128        $prev_time = date( 'Y-m-d H:i:s', $time - ( 121 * HOUR_IN_SECONDS ) );
     129
     130        $a = self::factory()->activity->create( array(
     131            'component'     => 'members',
     132            'type'          => 'new_avatar',
     133            'user_id'       => $u,
     134            'recorded_time' => $prev_time,
     135        ) );
     136
     137        bp_members_new_avatar_activity( $u );
     138
     139        $new_avatar_activities = bp_activity_get( array(
     140            'user_id'     => $u,
     141            'component'   => buddypress()->members->id,
     142            'type'        => 'new_avatar',
     143            'count_total' => 'count_query',
     144        ) );
     145
     146        $this->assertEquals( 2, $new_avatar_activities['total'] );
     147    }
    96148}
Note: See TracChangeset for help on using the changeset viewer.