Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/19/2021 03:58:09 PM (4 years ago)
Author:
imath
Message:

Improve SQL performance when updating/deleting a list of notifications

Instead of looping into a list of notifications to run an update/delete query for each notification, update/delete a list of notifications using a single query. Use primarly this change for message thread notifications and bulk notification actions.

Mainly introduces 2 new static methods to BP_Notifications_Notification:

  • BP_Notifications_Notification::update_id_list() let you update a list of notifications using their notification IDs or component item IDs.
  • BP_Notifications_Notification::delete_id_list() let you delete a list of notifications using their notification IDs or component item IDs.

Props oztaser

Fixes #8426

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/actions/bulk-manage.php

    r13091 r13112  
    1313 * @since 2.2.0
    1414 *
    15  * @return bool
     15 * @return false|void
    1616 */
    1717function bp_notifications_action_bulk_manage() {
     
    4343    switch ( $action ) {
    4444        case 'delete':
    45             foreach ( $notifications as $notification ) {
    46                 bp_notifications_delete_notification( $notification );
    47             }
     45            bp_notifications_delete_notifications_by_ids( $notifications );
    4846            bp_core_add_message( __( 'Notifications deleted.', 'buddypress' ) );
    4947            break;
    5048
    5149        case 'read':
    52             foreach ( $notifications as $notification ) {
    53                 bp_notifications_mark_notification( $notification, false );
    54             }
     50            bp_notifications_mark_notifications_by_ids( $notifications, false );
    5551            bp_core_add_message( __( 'Notifications marked as read', 'buddypress' ) );
    5652            break;
    5753
    5854        case 'unread':
    59             foreach ( $notifications as $notification ) {
    60                 bp_notifications_mark_notification( $notification, true );
    61             }
     55            bp_notifications_mark_notifications_by_ids( $notifications, true );
    6256            bp_core_add_message( __( 'Notifications marked as unread.', 'buddypress' ) );
    6357            break;
Note: See TracChangeset for help on using the changeset viewer.