Skip to:
Content

bbPress.org

Ticket #3395: 3395.5.diff

File 3395.5.diff, 7.1 KB (added by johnjamesjacoby, 4 years ago)

Constant removed. Default 1000.

  • src/includes/extend/akismet.php

     
    966966        }
    967967
    968968        /**
    969          * Deletes old spam topics & replies from the queue after 15 days
    970          * (determined by `_bbp_akismet_delete_spam_interval` filter).
     969         * Get the number of rows to delete in a single clean-up query.
    971970         *
    972          * @since 2.6.7 bbPress (r7203)
     971         * @since 2.6.9 bbPress (r7225)
    973972         *
    974          * @global wpdb $wpdb
     973         * @param string $filter The name of the filter to run
     974         * @return int
    975975         */
    976         public function delete_old_spam() {
    977                 global $wpdb;
     976        public function get_delete_limit( $filter = '' ) {
    978977
     978                // Default filter
     979                if ( empty( $filter ) ) {
     980                        $filter = '_bbp_akismet_delete_spam_limit';
     981                }
     982
    979983                /**
    980                  * Determines how many posts will be deleted in each batch.
     984                 * Determines how many rows will be deleted in each batch.
    981985                 *
    982                  * @param int The default as defined by AKISMET_DELETE_LIMIT (also used
    983                  *            in Akismet WordPress plugin).
     986                 * @param int The number of rows. Default 1000.
    984987                 */
    985                 $delete_limit = (int) apply_filters( '_bbp_akismet_delete_spam_limit',
    986                         defined( 'AKISMET_DELETE_LIMIT' )
    987                                 ? AKISMET_DELETE_LIMIT
    988                                 : 10000
    989                 );
     988                $delete_limit = (int) apply_filters( $filter, 1000 );
    990989
    991                 // Validate the deletion limit
    992                 $delete_limit = max( 1, intval( $delete_limit ) );
     990                // Validate and return the deletion limit
     991                return max( 1, $delete_limit );
     992        }
    993993
     994        /**
     995         * Get the interval (in days) for spam to remain in the queue.
     996         *
     997         * @since 2.6.9 bbPress (r7225)
     998         *
     999         * @param string $filter The name of the filter to run
     1000         * @return int
     1001         */
     1002        public function get_delete_interval( $filter = '' ) {
     1003
     1004                // Default filter
     1005                if ( empty( $filter ) ) {
     1006                        $filter = '_bbp_akismet_delete_spam_interval';
     1007                }
     1008
    9941009                /**
    9951010                 * Determines how many days a piece of spam will be left in the Spam
    9961011                 * queue before being deleted.
    9971012                 *
    998                  * @param int The default number of days.
     1013                 * @param int The number of days. Default 15.
    9991014                 */
    1000                 $delete_interval = (int) apply_filters( '_bbp_akismet_delete_spam_interval', 15 );
     1015                $delete_interval = (int) apply_filters( $filter, 15 );
    10011016
    1002                 // Validate the deletion interval
    1003                 $delete_interval = max( 1, intval( $delete_interval ) );
     1017                // Validate and return the deletion interval
     1018                return max( 1, $delete_interval );
     1019        }
    10041020
     1021        /**
     1022         * Deletes old spam topics & replies from the queue after 15 days
     1023         * (determined by `_bbp_akismet_delete_spam_interval` filter)
     1024         * since they are not useful in the long term.
     1025         *
     1026         * @since 2.6.7 bbPress (r7203)
     1027         *
     1028         * @global wpdb $wpdb
     1029         */
     1030        public function delete_old_spam() {
     1031                global $wpdb;
     1032
     1033                // Get the deletion limit & interval
     1034                $delete_limit    = $this->get_delete_limit( '_bbp_akismet_delete_spam_limit' );
     1035                $delete_interval = $this->get_delete_interval( '_bbp_akismet_delete_spam_interval' );
     1036
    10051037                // Setup the query
    10061038                $sql = "SELECT id FROM {$wpdb->posts} WHERE post_type IN ('topic', 'reply') AND post_status = 'spam' AND DATE_SUB(NOW(), INTERVAL %d DAY) > post_date_gmt LIMIT %d";
    10071039
     
    10341066
    10351067                        // Prepared as strings since id is an unsigned BIGINT, and using %
    10361068                        // will constrain the value to the maximum signed BIGINT.
    1037                         $format_string = implode( ", ", array_fill( 0, count( $spam_ids ), '%s' ) );
     1069                        $format_string = implode( ', ', array_fill( 0, count( $spam_ids ), '%s' ) );
    10381070
    10391071                        // Run the delete queries
    1040                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE post_id IN ( " . $format_string . " )", $spam_ids ) );
    1041                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ( " . $format_string . " )", $spam_ids ) );
     1072                        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE ID IN ( {$format_string} )", $spam_ids ) );
     1073                        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ( {$format_string} )", $spam_ids ) );
    10421074
    10431075                        // Clean the post cache for these topics & replies
    10441076                        clean_post_cache( $spam_ids );
     
    10681100        }
    10691101
    10701102        /**
    1071          * Deletes `_bbp_akismet_as_submitted` meta keys after 15 days, since they
    1072          * are large and not useful in the long term.
     1103         * Deletes `_bbp_akismet_as_submitted` meta keys after 15 days
     1104         * (determined by `_bbp_akismet_delete_spam_meta_interval` filter)
     1105         * since they are large and not useful in the long term.
    10731106         *
    10741107         * @since 2.6.7 bbPress (r7203)
    10751108         *
     
    10781111        public function delete_old_spam_meta() {
    10791112                global $wpdb;
    10801113
    1081                 /**
    1082                  * Determines how many days a piece of spam will be left in the Spam
    1083                  * queue before being deleted.
    1084                  *
    1085                  * @param int The default number of days.
    1086                  */
    1087                 $interval = (int) apply_filters( '_bbp_akismet_delete_spam_meta_interval', 15 );
     1114                // Get the deletion limit & interval
     1115                $delete_limit    = $this->get_delete_limit( '_bbp_akismet_delete_spam_meta_limit' );
     1116                $delete_interval = $this->get_delete_interval( '_bbp_akismet_delete_spam_meta_interval' );
    10881117
    1089                 // Validate the deletion interval
    1090                 $interval = max( 1, intval( $interval ) );
    1091 
    10921118                // Setup the query
    1093                 $sql = "SELECT m.post_id FROM {$wpdb->postmeta} as m INNER JOIN {$wpdb->posts} as p ON m.post_id = p.id WHERE m.meta_key = '_bbp_akismet_as_submitted' AND DATE_SUB(NOW(), INTERVAL %d DAY) > p.post_date_gmt LIMIT 10000";
     1119                $sql = "SELECT m.post_id FROM {$wpdb->postmeta} as m INNER JOIN {$wpdb->posts} as p ON m.post_id = p.ID WHERE m.meta_key = '_bbp_akismet_as_submitted' AND DATE_SUB(NOW(), INTERVAL %d DAY) > p.post_date_gmt LIMIT %d";
    10941120
    10951121                // Query loop of topic & reply IDs
    1096                 while ( $spam_ids = $wpdb->get_col( $wpdb->prepare( $sql, $interval ) ) ) {
     1122                while ( $spam_ids = $wpdb->get_col( $wpdb->prepare( $sql, $delete_interval, $delete_limit ) ) ) {
    10971123
    10981124                        // Exit loop if no spam IDs
    10991125                        if ( empty( $spam_ids ) ) {
     
    11341160        }
    11351161
    11361162        /**
    1137          * Clears post meta that no longer has corresponding posts in the database.
     1163         * Clears post meta that no longer has corresponding posts in the database
     1164         * (determined by `_bbp_akismet_delete_spam_orphaned_limit` filter)
     1165         * since it is not useful in the long term.
    11381166         *
    11391167         * @since 2.6.7 bbPress (r7203)
    11401168         *
     
    11431171        public function delete_orphaned_spam_meta() {
    11441172                global $wpdb;
    11451173
     1174                // Get the deletion limit
     1175                $delete_limit = $this->get_delete_limit( '_bbp_akismet_delete_spam_orphaned_limit' );
     1176
     1177                // Default last meta ID
    11461178                $last_meta_id = 0;
    11471179
    11481180                // Start time (float)
     
    11541186                $max_exec_time = (float) max( ini_get( 'max_execution_time' ) - 5, 3 );
    11551187
    11561188                // Setup the query
    1157                 $sql = "SELECT m.meta_id, m.post_id, m.meta_key FROM {$wpdb->postmeta} as m LEFT JOIN {$wpdb->posts} as p ON m.post_id = p.id WHERE p.id IS NULL AND m.meta_id > %d ORDER BY m.meta_id LIMIT 1000";
     1189                $sql = "SELECT m.meta_id, m.post_id, m.meta_key FROM {$wpdb->postmeta} as m LEFT JOIN {$wpdb->posts} as p ON m.post_id = p.ID WHERE p.ID IS NULL AND m.meta_id > %d ORDER BY m.meta_id LIMIT %d";
    11581190
    11591191                // Query loop of topic & reply IDs
    1160                 while ( $spam_meta_results = $wpdb->get_results( $wpdb->prepare( $sql, $last_meta_id ) ) ) {
     1192                while ( $spam_meta_results = $wpdb->get_results( $wpdb->prepare( $sql, $last_meta_id, $delete_limit ) ) ) {
    11611193
    11621194                        // Exit loop if no spam IDs
    11631195                        if ( empty( $spam_meta_results ) ) {