Plugin Directory

Changeset 2940115


Ignore:
Timestamp:
07/19/2023 02:29:15 AM (3 years ago)
Author:
deryck
Message:

Performance improved while deleting old events

Location:
logdash-activity-log/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • logdash-activity-log/trunk/README.txt

    r2916058 r2940115  
    66Tested up to: 6.2
    77Requires PHP: 7.4
    8 Stable tag: 1.1.2
     8Stable tag: 1.1.3
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7676== Changelog ==
    7777
     78= 1.1.3 =
     79* Performance improved while deleting old events
     80
    7881= 1.1.2 =
    7982* Fixed a critical bug with Autoload
     
    8992== Upgrade Notice ==
    9093
     94= 1.1.3 =
     95* Performance improved while deleting old events
     96
    9197= 1.1.2 =
    9298* Fixed a critical bug with Autoload
  • logdash-activity-log/trunk/logdash-activity-log.php

    r2916058 r2940115  
    99 * Plugin URI:        https://deryckoe.com/logdash-activity-log
    1010 * Description:       The ultimate solution for tracking activities and security issues on your WordPress site.
    11  * Version:           1.1.2
     11 * Version:           1.1.3
    1212 * Author:            Deryck Oñate
    1313 * Author URI:        http://deryckoe.com
     
    2727 * Currently plugin version.
    2828 */
    29 define( 'LOGDASH_VERSION', '1.1.2' );
     29define( 'LOGDASH_VERSION', '1.1.3' );
    3030
    3131/**
  • logdash-activity-log/trunk/src/Actions/RemoveExpiredLog.php

    r2916051 r2940115  
    1212    public function __construct() {
    1313        global $wpdb;
    14         $this->wpdb   = $wpdb;
     14        $this->wpdb = $wpdb;
    1515    }
    1616
     
    2828
    2929    public function actions() {
    30         add_action( 'init', [ $this, 'delete_expired_log' ] );
     30
     31//      add_action( 'init', [ $this, 'delete_expired_log' ] );
     32        add_action( 'init', [ $this, 'register_expired_log_job' ] );
     33        add_action( 'delete_expired_log', [ $this, 'delete_expired_log' ] );
     34    }
     35
     36    public function register_expired_log_job(  ) {
     37        if ( ! wp_next_scheduled( 'delete_expired_log' ) ) {
     38            wp_schedule_single_event( time(), 'delete_expired_log' );
     39        }
    3140    }
    3241
    3342    public function delete_expired_log() {
    34 
    3543        $options = $this->get_options();
    3644
     
    4250        $activity_log  = DB::log_table();
    4351        $activity_meta = DB::meta_table();
    44         $site_id = get_current_blog_id();
     52        $site_id       = get_current_blog_id();
    4553
    46         $this->wpdb->query( "DELETE l FROM $activity_log l
    47                                LEFT JOIN $activity_meta m
    48                                  ON l.ID = m.event_id
    49                                WHERE FROM_UNIXTIME(l.created, '%Y-%m-%d') < DATE_SUB(CURRENT_DATE, INTERVAL {$days} DAY) AND site_id = {$site_id};" );
     54        $this->wpdb->query( "DELETE FROM $activity_log WHERE FROM_UNIXTIME(created, '%Y-%m-%d') < DATE_SUB(CURRENT_DATE, INTERVAL {$days} DAY) AND {$site_id} = 1;" );
     55        $this->wpdb->query( "DELETE FROM $activity_meta WHERE NOT EXISTS ( SELECT 1 FROM $activity_log WHERE $activity_log.ID = $activity_meta.event_id);" );
    5056
    5157        $rows_affected = $this->wpdb->rows_affected;
     
    5561        }
    5662
    57         update_option('logdash_deleted_events', [
     63        update_option( 'logdash_deleted_events', [
    5864            'rows' => $rows_affected,
    5965            'date' => time(),
Note: See TracChangeset for help on using the changeset viewer.