Skip to:
Content

BuddyPress.org

Ticket #7130: 7130-counts.diff

File 7130-counts.diff, 3.0 KB (added by boonebgorges, 7 years ago)
  • src/bp-notifications/bp-notifications-cache.php

    diff --git src/bp-notifications/bp-notifications-cache.php src/bp-notifications/bp-notifications-cache.php
    index 3d59e770f..981190052 100644
    function bp_notifications_update_meta_cache( $notification_ids = false ) { 
    4343 */
    4444function bp_notifications_clear_all_for_user_cache( $user_id = 0 ) {
    4545        wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' );
     46        wp_cache_delete( $user_id, 'bp_notifications_unread_count' );
    4647}
    4748
    4849/**
  • src/bp-notifications/bp-notifications-functions.php

    diff --git src/bp-notifications/bp-notifications-functions.php src/bp-notifications/bp-notifications-functions.php
    index 09831f9f1..dd20212ad 100644
    function bp_notifications_check_notification_access( $user_id, $notification_id 
    607607 * @return int Unread notification count.
    608608 */
    609609function bp_notifications_get_unread_notification_count( $user_id = 0 ) {
    610         $notifications = bp_notifications_get_all_notifications_for_user( $user_id );
    611         $count         = ! empty( $notifications ) ? count( $notifications ) : 0;
     610        if ( empty( $user_id ) ) {
     611                $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
     612        }
     613
     614        $count = wp_cache_get( $user_id, 'bp_notifications_unread_count' );
     615        if ( false === $count ) {
     616                $count = BP_Notifications_Notification::get_total_count( array(
     617                        'user_id' => $user_id,
     618                        'is_new'  => true,
     619                ) );
     620                wp_cache_set( $user_id, $count, 'bp_notifications_unread_count' );
     621        }
    612622
    613623        /**
    614624         * Filters the count of unread notification items for a user.
  • tests/phpunit/testcases/notifications/functions.php

    diff --git tests/phpunit/testcases/notifications/functions.php tests/phpunit/testcases/notifications/functions.php
    index ee1b01a76..89b83fd14 100644
    class BP_Tests_Notifications_Functions extends BP_UnitTestCase { 
    3535                ) );
    3636
    3737                $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );
     38                $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );
    3839        }
    3940
    4041        /**
    class BP_Tests_Notifications_Functions extends BP_UnitTestCase { 
    6162                BP_Notifications_Notification::delete( array( 'id' => $n1, ) );
    6263
    6364                $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );
     65                $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );
    6466        }
    6567
    6668        /**
    class BP_Tests_Notifications_Functions extends BP_UnitTestCase { 
    9193                );
    9294
    9395                $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );
     96                $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );
    9497        }
    9598
    9699        /**
    class BP_Tests_Notifications_Functions extends BP_UnitTestCase { 
    121124                );
    122125
    123126                $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );
     127                $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) );
    124128        }
    125129
    126130        /**