Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/21/2015 07:56:59 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Notifications: Improve all_for_user cache deletion.

  • Introduce bp_notification_before_update action which fires before a Notification is updated
  • Introduce bp_notifications_clear_all_for_user_cache() as wrapper for wp_cache_delete() with appropriate cache group and key
  • Introduce bp_notifications_clear_all_for_user_cache_before_update() hooked to bp_notification_before_update action, to handle cache deletion before a notification is updated

This change fixes a bug where marking single notifications as read/unread would not show anticipated results, as the all_for_user cache was not being properly cleared.

Props r-a-y. Fixes #6445.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/classes/class-bp-notifications-notification.php

    r9819 r9887  
    831831        $where  = self::get_query_clauses( $where_args  );
    832832
    833         // make sure we delete the notification cache for the user on update
    834         if ( ! empty( $where_args['user_id'] ) ) {
    835             wp_cache_delete( 'all_for_user_' . $where_args['user_id'], 'bp_notifications' );
    836         }
    837 
    838         return self::_update( $update['data'], $where['data'], $update['format'], $where['format'] );
     833        /**
     834         * Fires before the update of a notification item.
     835         *
     836         * @since BuddyPress (2.3.0)
     837         *
     838         * @param array $update_args See BP_Notifications_Notification::update().
     839         * @param array $where_args  See BP_Notifications_Notification::update().
     840         */
     841        do_action( 'bp_notification_before_update', $update_args, $where_args );
     842
     843        return self::_update(
     844            $update['data'],
     845            $where['data'],
     846            $update['format'],
     847            $where['format']
     848        );
    839849    }
    840850
Note: See TracChangeset for help on using the changeset viewer.