Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/05/2018 12:57:24 PM (6 years ago)
Author:
boonebgorges
Message:

Move notification-grouping logic to MySQL.

The notification-grouping logic required to show the collapsed Notifications
toolbar - "You have 3 pending friend requests", etc - is currently done in
PHP, in a manner that requires all notifications to be loaded into memory
and processed. On sites where users have large numbers of notifications, this
operation requires extensive resources. By leaving the grouping to MySQL,
we can speed up processing in almost all situations.

This changeset also adds specific caching for grouped notifications.

Props m_uysl.
See #7130.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/notifications/functions.php

    r11851 r11888  
    404404        $this->n_args = compact( 'action', 'item_id', 'secondary_item_id', 'total_items', 'id', 'format' );
    405405    }
     406
     407    /**
     408     * @group cache
     409     * @ticket BP7130
     410     */
     411    public function test_get_grouped_notifications_for_user_cache_invalidation() {
     412        $u = self::factory()->user->create();
     413
     414        $n1 = self::factory()->notification->create( array(
     415            'component_name'    => 'activity',
     416            'component_action'  => 'new_at_mention',
     417            'item_id'           => 99,
     418            'user_id'           => $u,
     419        ) );
     420
     421        // Prime cache.
     422        $found = bp_notifications_get_grouped_notifications_for_user( $u );
     423        $this->assertEquals( 1, $found[0]->total_count );
     424
     425        $n2 = self::factory()->notification->create( array(
     426            'component_name'    => 'activity',
     427            'component_action'  => 'new_at_mention',
     428            'item_id'           => 100,
     429            'user_id'           => $u,
     430        ) );
     431
     432        $found = bp_notifications_get_grouped_notifications_for_user( $u );
     433        $this->assertEquals( 2, $found[0]->total_count );
     434    }
    406435}
Note: See TracChangeset for help on using the changeset viewer.