Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/08/2018 03:20:59 PM (7 years ago)
Author:
boonebgorges
Message:

Notifications: User count query should be separately fetched and cached.

Previously, notification counts were calculated by fetching the entire
notification objects.

Props m_uysl.
See #7130.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/bp-notifications-functions.php

    r11447 r11851  
    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    /**
Note: See TracChangeset for help on using the changeset viewer.