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/template.php

    r8402 r8491  
    376376        $activities_template = null;
    377377    }
     378
     379    /**
     380     * @group bp_activity_has_more_items
     381     */
     382    public function test_bp_activity_has_more_items_no_count_total_false() {
     383        $a1 = $this->factory->activity->create();
     384        $a2 = $this->factory->activity->create();
     385
     386        $args = array(
     387            'count_total' => false,
     388        );
     389
     390        if ( bp_has_activities( $args ) ) {
     391            global $activities_template;
     392            $this->assertFalse( bp_activity_has_more_items() );
     393            $activities_template = null;
     394        }
     395    }
     396
     397    /**
     398     * @group bp_activity_has_more_items
     399     */
     400    public function test_bp_activity_has_more_items_no_count_total_true() {
     401        $a1 = $this->factory->activity->create();
     402        $a2 = $this->factory->activity->create();
     403        $a3 = $this->factory->activity->create();
     404        $a4 = $this->factory->activity->create();
     405
     406        $args = array(
     407            'count_total' => false,
     408            'per_page' => 2,
     409        );
     410
     411        if ( bp_has_activities( $args ) ) {
     412            global $activities_template;
     413            $this->assertTrue( bp_activity_has_more_items() );
     414            $activities_template = null;
     415        }
     416    }
     417
     418    /**
     419     * @group bp_activity_has_more_items
     420     */
     421    public function test_bp_activity_has_more_items_count_total_false() {
     422        $a1 = $this->factory->activity->create();
     423        $a2 = $this->factory->activity->create();
     424        $a3 = $this->factory->activity->create();
     425        $a4 = $this->factory->activity->create();
     426
     427        $args = array(
     428            'count_total' => 'count_query',
     429        );
     430
     431        if ( bp_has_activities( $args ) ) {
     432            global $activities_template;
     433            $this->assertFalse( bp_activity_has_more_items() );
     434            $activities_template = null;
     435        }
     436    }
     437
     438    /**
     439     * @group bp_activity_has_more_items
     440     */
     441    public function test_bp_activity_has_more_items_count_total_true() {
     442        $a1 = $this->factory->activity->create();
     443        $a2 = $this->factory->activity->create();
     444        $a3 = $this->factory->activity->create();
     445        $a4 = $this->factory->activity->create();
     446
     447        $args = array(
     448            'count_total' => 'count_query',
     449            'per_page' => 2,
     450        );
     451
     452        if ( bp_has_activities( $args ) ) {
     453            global $activities_template;
     454            $this->assertTrue( bp_activity_has_more_items() );
     455            $activities_template = null;
     456        }
     457    }
    378458}
Note: See TracChangeset for help on using the changeset viewer.