Skip to:
Content

BuddyPress.org

Changeset 5622


Ignore:
Timestamp:
01/07/2012 05:23:24 PM (13 years ago)
Author:
djpaul
Message:

Activity Akismet now tidies up old meta. Fixes #3906

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-akismet.php

    r5621 r5622  
    464464        remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
    465465
     466        // Get the response
    466467        $activity_data['bp_as_result'] = $response[1];
    467468
     469        // Perform a daily tidy up
     470        if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) )
     471            wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' );
     472
    468473        return $activity_data;
    469474    }
     
    473478     *
    474479     * @param string $user_agent
    475      * @since 1.0
     480     * @since 1.6
    476481     */
    477482    public function buddypress_ua( $user_agent ) {
     
    515520    }
    516521}
     522
     523/**
     524 * Deletes old spam activity meta data, as _bp_akismet_submission meta can be large.
     525 *
     526 * @global object $bp BuddyPress global settings
     527 * @global wpdb $wpdb WordPress database object
     528 * @since 1.6
     529 */
     530function bp_activity_akismet_delete_old_metadata() {
     531    global $bp, $wpdb;
     532
     533    $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 );
     534
     535    // Enforce a minimum of 1 day
     536    $interval = max( 1, absint( $interval ) );
     537
     538    // _bp_akismet_submission meta values are large, so expire them after $interval days regardless of the activity status
     539    $sql          = $wpdb->prepare( "SELECT a.id FROM {$bp->activity->table_name} a LEFT JOIN {$bp->activity->table_name_meta} m ON a.id = m.activity_id WHERE m.meta_key = %s AND DATE_SUB(%s, INTERVAL {$interval} DAY) > a.date_recorded LIMIT 10000", '_bp_akismet_submission', current_time( 'mysql', 1 ) );
     540    $activity_ids = $wpdb->get_col( $sql );
     541
     542    if ( ! empty( $activity_ids ) ) {
     543        foreach ( $activity_ids as $activity_id )
     544            bp_activity_delete_meta( $activity_id, '_bp_akismet_submission' );
     545    }
     546}
    517547?>
Note: See TracChangeset for help on using the changeset viewer.