• Resolved Chris Lloyd

    (@chrisl27)


    Hiya,

    Currently the tracker uses update_option to update the current visit ID for every new visitor. If you mainly have new visitors (or new visits) then every hit generates an extra database update on top of the actual stat record.

    I recommend the below diff that will improve performance for people using WordPress with a high-speed transient backend like memcached. This is a simple change since the code already copes with the fact that the transient might have been cleared.

    
    --- wp-slimstat-old/wp-slimstat.php     2017-05-08 00:35:30.000000000 +0100
    +++ wp-slimstat/wp-slimstat.php 2017-05-22 19:55:41.000000000 +0100
    @@ -1009,12 +1009,12 @@
                    if ( $is_new_session && ( $_force_assign || self::$settings[ 'javascript_mode' ] == 'yes' ) ) {
                            if ( empty( self::$settings[ 'session_duration' ] ) ) self::$settings[ 'session_duration' ] = 1800;
     
    -                       self::$stat[ 'visit_id' ] = get_option( 'slimstat_visit_id', -1 );
    -                       if ( self::$stat[ 'visit_id' ] == -1 ) {
    +                       self::$stat[ 'visit_id' ] = get_transient( 'slimstat_visit_id' );
    +                       if ( self::$stat[ 'visit_id' ] === false ) {
                                    self::$stat[ 'visit_id' ] = intval( self::$wpdb->get_var( "SELECT MAX( visit_id ) FROM {$GLOBALS[ 'wpdb' ]->prefix}slim_stats" ) );
                            }
                            self::$stat[ 'visit_id' ]++;
    -                       update_option( 'slimstat_visit_id', self::$stat[ 'visit_id' ] );
    +                       set_transient( 'slimstat_visit_id', self::$stat[ 'visit_id' ] );
     
                            $is_set_cookie = apply_filters( 'slimstat_set_visit_cookie', true );
                            if ( $is_set_cookie ) {
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jason Crouse

    (@coolmann)

    Hi Chris,

    I will forward your message to the developer for his review. Stay tuned!

    Jason

    Plugin Author Jason Crouse

    (@coolmann)

    Hi Chris,

    Just a quick update to let you know that your diff has been applied to the next update. Thank you for helping us improve Slimstat.

    Best,
    Jason

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Recommend switching slimstat_visit_id to use a transient’ is closed to new replies.