$interval = 1;
// akismet_as_submitted meta values are large, so expire them
// after $interval days regardless of the comment status
while ( $comment_ids =
$wpdb->
get_col( $wpdb->
prepare( "SELECT m.comment_id FROM {
$wpdb->commentmeta
} as m INNER JOIN {
$wpdb->comments
} as c USING(comment_id) WHERE m.meta_key = 'akismet_as_submitted' AND DATE_SUB(NOW(), INTERVAL %d DAY) > c.comment_date_gmt LIMIT 10000",
$interval ) ) ) { if ( empty( $comment_ids ) ) return;
$wpdb->queries = array
();
foreach ( $comment_ids as $comment_id ) { delete_comment_meta( $comment_id, 'akismet_as_submitted'
);
do_action( 'akismet_batch_delete_count', __FUNCTION__
);
} do_action( 'akismet_delete_commentmeta_batch',
is_countable( $comment_ids ) ?
count( $comment_ids ) : 0
);
} if ( apply_filters( 'akismet_optimize_table',
( mt_rand(1, 5000
) == 11
),
$wpdb->commentmeta
) ) // lucky number
$wpdb->
query("OPTIMIZE TABLE {
$wpdb->commentmeta
}"
);
} // Clear out comments meta that no longer have corresponding comments in the database