Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/09/2014 06:33:05 PM (8 years ago)
Author:
boonebgorges
Message:

Disable COUNT queries by default in bp_activity_get() stack

The COUNT query performed to get the total activity count has proven to be a
performance bottleneck on large sites. Moreover, the way that activity items
are displayed on the front end (using the Load More link) means that the total
count is not actually used by BuddyPress in most cases. To reduce query
overhead, we introduce a 'count_total' parameter to the bp_activity_get()
stack, and set it to false by default.

For backward compatibility, a few additional changes are introduced:

  • In the activity-loop.php template, the <noscript> pagination markup is removed. In its place, the Load More link is refactored so that it loads the next available page of activity items.
  • The mechanism used to determine whether there are more activity items to show (bp_activity_has_more_items()) has been refined; when no COUNT query takes place, we query for the $per_page value + 1 to infer whether more items are available.

Fixes #5629

Props boonebgorges, r-a-y

File:
1 edited

Legend:

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

    r8251 r8491  
    136136                ),
    137137            ),
     138            'count_total' => 'count_query',
    138139        ) );
    139140
     
    312313
    313314    /**
     315     * @group get
     316     * @group count_total
     317     */
     318    public function test_get_with_count_total() {
     319        $a1 = $this->factory->activity->create();
     320        $a2 = $this->factory->activity->create();
     321
     322        $activity = BP_Activity_Activity::get( array(
     323            'count_total' => 'count_query',
     324        ) );
     325
     326        $this->assertEquals( 2, $activity['total'] );
     327    }
     328
     329    /**
     330     * @group get
     331     * @group count_total
     332     */
     333    public function test_get_with_count_total_false() {
     334        $a1 = $this->factory->activity->create();
     335        $a2 = $this->factory->activity->create();
     336
     337        $activity = BP_Activity_Activity::get( array(
     338            'count_total' => false,
     339        ) );
     340
     341        $this->assertSame( null, $activity['total'] );
     342    }
     343
     344    /**
     345     * @group get
     346     * @group count_total
     347     */
     348    public function test_get_with_count_total_default_to_false() {
     349        $a1 = $this->factory->activity->create();
     350        $a2 = $this->factory->activity->create();
     351
     352        $activity = BP_Activity_Activity::get();
     353
     354        $this->assertSame( null, $activity['total'] );
     355    }
     356
     357    /**
    314358     * @group get_id
    315359     */
Note: See TracChangeset for help on using the changeset viewer.