From e9541a8de0fd8f8a5e5a6d1fa7f11c0b6273da69 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 21 Jun 2024 15:16:35 +0100 Subject: [PATCH 1/2] Add some handling in ignore method to support ignoring large batches with an alternative query --- admin/class-ajax.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/admin/class-ajax.php b/admin/class-ajax.php index 8d3928df..e5c54695 100644 --- a/admin/class-ajax.php +++ b/admin/class-ajax.php @@ -661,9 +661,27 @@ function ( $value ) { $ignre_comment = ( 'enable' === $action && isset( $_REQUEST['comment'] ) ) ? sanitize_textarea_field( $_REQUEST['comment'] ) : null; $ignore_global = ( 'enable' === $action && isset( $_REQUEST['ignore_global'] ) ) ? sanitize_textarea_field( $_REQUEST['ignore_global'] ) : 0; - foreach ( $ids as $id ) { + // If largeBatch is set and 'true', we need to perform an update using the 'object' + // instead of IDs. It is a much less efficient query than by IDs - but many IDs run + // into request size limits which caused this to not function at all. + if ( isset( $_REQUEST['largeBatch'] ) && 'true' === $_REQUEST['largeBatch'] ) { + // Get the 'object' from the first id. + $first_id = $ids[0]; + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to get the latest value, not a cached value. + $object = $wpdb->get_var( $wpdb->prepare( 'SELECT object FROM %i WHERE id = %d', $table_name, $first_id ) ); + + if ( ! $object ) { + $error = new \WP_Error( '-2', 'No ignore data to return' ); + wp_send_json_error( $error ); + } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation. - $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and id = %d', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $id ) ); + $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and object = %s', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $object ) ); + } else { + // for small batches of IDs, we can just loop through + foreach ( $ids as $id ) { + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation. + $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and object = %d', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $id ) ); + } } $data = [ From b5726794a1b161966a72fc9291ccb28633bae4a6 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 21 Jun 2024 16:33:15 +0100 Subject: [PATCH 2/2] Fix comment missing full stop --- admin/class-ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/class-ajax.php b/admin/class-ajax.php index e5c54695..f907e80b 100644 --- a/admin/class-ajax.php +++ b/admin/class-ajax.php @@ -677,7 +677,7 @@ function ( $value ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation. $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and object = %s', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $object ) ); } else { - // for small batches of IDs, we can just loop through + // For small batches of IDs, we can just loop through. foreach ( $ids as $id ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation. $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and object = %d', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $id ) );