Skip to content

Commit

Permalink
Merge pull request #675 from equalizedigital/william/no-issue/add-han…
Browse files Browse the repository at this point in the history
…dling-for-large-batch-ignores

Add some handling in ignore method to support ignoring large batches …
  • Loading branch information
pattonwebz committed Jun 24, 2024
2 parents fc29bc7 + b572679 commit 230eb68
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions admin/class-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,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 = [
Expand Down

0 comments on commit 230eb68

Please sign in to comment.