Changeset 7226
- Timestamp:
- 11/29/2021 03:08:21 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/extend/akismet.php
r7206 r7226 967 967 968 968 /** 969 * Deletes old spam topics & replies from the queue after 15 days 970 * (determined by `_bbp_akismet_delete_spam_interval` filter). 971 * 972 * @since 2.6.7 bbPress (r7203) 973 * 974 * @global wpdb $wpdb 975 */ 976 public function delete_old_spam() { 977 global $wpdb; 969 * Get the number of rows to delete in a single clean-up query. 970 * 971 * @since 2.6.9 bbPress (r7225) 972 * 973 * @param string $filter The name of the filter to run. 974 * @return int 975 */ 976 public function get_delete_limit( $filter = '' ) { 977 978 // Default filter 979 if ( empty( $filter ) ) { 980 $filter = '_bbp_akismet_delete_spam_limit'; 981 } 978 982 979 983 /** 980 * Determines how many posts will be deleted in each batch.984 * Determines how many rows will be deleted in each batch. 981 985 * 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. 984 987 */ 985 $delete_limit = (int) apply_filters( '_bbp_akismet_delete_spam_limit', 986 defined( 'AKISMET_DELETE_LIMIT' ) 987 ? AKISMET_DELETE_LIMIT 988 : 10000 989 ); 990 991 // Validate the deletion limit 992 $delete_limit = max( 1, intval( $delete_limit ) ); 988 $delete_limit = (int) apply_filters( $filter, 1000 ); 989 990 // Validate and return the deletion limit 991 return max( 1, $delete_limit ); 992 } 993 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 } 993 1008 994 1009 /** … … 996 1011 * queue before being deleted. 997 1012 * 998 * @param int The default number of days.1013 * @param int The number of days. Default 15. 999 1014 */ 1000 $delete_interval = (int) apply_filters( '_bbp_akismet_delete_spam_interval', 15 ); 1001 1002 // Validate the deletion interval 1003 $delete_interval = max( 1, intval( $delete_interval ) ); 1015 $delete_interval = (int) apply_filters( $filter, 15 ); 1016 1017 // Validate and return the deletion interval 1018 return max( 1, $delete_interval ); 1019 } 1020 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' ); 1004 1036 1005 1037 // Setup the query … … 1035 1067 // Prepared as strings since id is an unsigned BIGINT, and using % 1036 1068 // 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' ) ); 1038 1070 1039 1071 // 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 ) ); 1042 1074 1043 1075 // Clean the post cache for these topics & replies … … 1069 1101 1070 1102 /** 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. 1073 1106 * 1074 1107 * @since 2.6.7 bbPress (r7203) … … 1079 1112 global $wpdb; 1080 1113 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 ); 1088 1089 // Validate the deletion interval 1090 $interval = max( 1, intval( $interval ) ); 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' ); 1091 1117 1092 1118 // 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"; 1094 1120 1095 1121 // 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 ) ) ) { 1097 1123 1098 1124 // Exit loop if no spam IDs … … 1135 1161 1136 1162 /** 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. 1138 1166 * 1139 1167 * @since 2.6.7 bbPress (r7203) … … 1144 1172 global $wpdb; 1145 1173 1174 // Get the deletion limit 1175 $delete_limit = $this->get_delete_limit( '_bbp_akismet_delete_spam_orphaned_limit' ); 1176 1177 // Default last meta ID 1146 1178 $last_meta_id = 0; 1147 1179 … … 1155 1187 1156 1188 // 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"; 1158 1190 1159 1191 // 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 ) ) ) { 1161 1193 1162 1194 // Exit loop if no spam IDs
Note: See TracChangeset
for help on using the changeset viewer.