• Resolved Paul

    (@paulschiretz)


    Hi,

    I’m using your plugin as the shortcode version. I’m currently doing a lot of cleanup of db queries and some optimizations. I noticed that your plugin checks if the AWS_INDEX_TABLE exists on every pageview and if i would use your shortcode more than once it would check for each of them… The reason is that the check for the table is right at the beginning of the markup function in the class-aws-markup.php class:

            public function markup() {

    global $wpdb;

    $table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;

    if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) != $table_name ) {
    if ( current_user_can( AWS_Helpers::user_admin_capability() ) ) {
    echo 'Please go to <a href="' . admin_url( 'admin.php?page=aws-options' ) . '">plugins settings page</a> and click on "Reindex table" button.';
    }
    return;
    }

    Is it really necessary to check on every shortcode call if the same table exists? wouldn’t it be enough to check once on the plugins_loaded hook?

    Or what i did in one of my plugins:
    set a transient if the tables exist, that expires after DAY_IN_SECONDS and only check again if it expired.


    In the plugins_loaded hook:

    get_transient( “aws_tables_exist” );
    check if the transient exists, all good. Otherwise:
    Check if the table exists and if so call set_transient(“transient_name”,”true”,DAY_IN_SECONDS )

    Short improvised(untested) code outline ??

    $transient_key = 'aws_index_tables_exists'; //don't no how you prefix your options..
    if( get_transient( $transient_key ) === false ) {
    global $wpdb;
    $table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;

    if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) != $table_name ) {
    //TODO: log the error, if possible(NOT A MUST)somehow store an admin notice not sure if that's currently implemented in your plugin... and is a pain in wp.
    }
    else {
    set_transient($transient_key,"true",DAY_IN_SECONDS );
    }
    }

    I know it’s a small issue but i can see room to improvement here! Otherwise I need to say I’m using your plugin since 5years now and it never disappoints!! ??

    Cheers,
    Paul

    • This topic was modified 3 weeks, 2 days ago by Paul.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Paul

    (@paulschiretz)

    Or easier, sorry to have spoiled you before… Can we have a filter to disable the check in the markup() function as you eitherway check for the index table in all the helper functions? I guess that would be the best solution! Cheers, Paul

    Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Thanks for letting me know about this problem. I will definitely fix this somehow in the next plugin release.

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.