• Resolved rossfabio

    (@rossfabio)


    Every time the plugin sends a notification for a new WooCommerce Order, it creates a record on the Options database table with name like nftb_new_order_id_for_notification_{order id}

    It seems like this serves no further purpose, if i delete them nothing happens.

    It would be best to add an instruction to remove them after they served their purpose because i’ve left the plugin running for a year and it created about 5 thousands records which are set on autoload and progressively slow down the website

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author rainafarai

    (@rainafarai)

    Hi

    It is a flag that I use to avoid sending duplicate notifications for each order; I don’t think they take up much space in your database.

    anyway you can clean them… nothing will happen !!

    This little snippet can help you to clean these options, Run ONCE or when you need in function.php

    $args = array(
    'post_type' => 'shop_order',
    'posts_per_page' => -1,
    'post_status' => 'any',
    );

    $orders = get_posts($args);


    foreach ($orders as $order) {
    $order_id = $order->ID;
    delete_option('nftb_new_order_id_for_notification_' . $order_id);
    }


    Bye


    Plugin Author rainafarai

    (@rainafarai)

    You should find a record for every order in the database, so more than 5,000 records means there are more than 5,000 orders. The issue that will be fixed in the next release is the autoload settings. I will set autoload to “none” so that records are not loaded into memory unless needed.

    thx

    Thread Starter rossfabio

    (@rossfabio)

    Hi @rainafarai , thank you very much for your response and for the work you’ve put into this plugin! Yes the thing that was bugging me was the autoload more than the database space, thank you also for the snippet!

    I took a look at the plugin files and there appear to be a delete option function already, but for some reason it is not doing its job properly, maybe it fires before the option gets registered on the database?

    In the meantime I have been using this other snippet which i find more direct, it doesn’t seem to interfere with new notifications and can run on a regular basis, and i run it every time i open the admin panel (a bit overkill, but i have other cleanup queries built into this function as well)

    function wr24_remove_unwanted_options() {
    global $wpdb;
    $options_table = $wpdb->prefix . 'options';

    $wpdb->query(
    "DELETE FROM $options_table WHERE
    option_name LIKE 'nftb_new_order_id_for_notification_%'"
    );
    }
    add_action('admin_init', 'wr24_remove_unwanted_options');

    cheers,
    Fabio

    Plugin Author rainafarai

    (@rainafarai)

    Ciao Fabio ho sistemato il problema nella ultima versione 3.4 !!

    Thread Starter rossfabio

    (@rossfabio)

    Grandissimo! Grazie mille!

    Plugin Author rainafarai

    (@rainafarai)

    Risolto cosi ….Ogni volta che viene inviato un ordine lancia questa funzione
    Vede se ci sono le option in autoload nel caso le mette in off auoload cosi da non prendere memoria e mette un flag cosi na non ripetere ancora la query di fix

    Grazie ancora per la segnalazione

    Se puoi grande favore lasci un recensione per il plug !! Nessun guadagno ma almeno soddisfazioni !!

    grazie

    function nftb_optimize_nftb_plugin_database() {
    global $wpdb;


    // Controlla se l'operazione è già stata eseguita
    if ( get_option( 'nftb_fix_1' ) === '1' ) {
    //error_log( 'Notification for Telegram - The operation nftb_new_order_id_for_notification_ set autoload to none has already been completed. No changes are necessary.' );
    return; // Termina l'esecuzione della funzione
    }

    $option_prefix = 'nftb_new_order_id_for_notification_';

    // Esegui la query per aggiornare il campo autoload a 'none'
    $rows_affected = $wpdb->query(
    $wpdb->prepare(
    "UPDATE {$wpdb->options}
    SET autoload = %s
    WHERE option_name LIKE %s",
    'off', // Valore per il campo autoload
    $option_prefix . '%' // Pattern per il nome delle opzioni
    )
    );


    if ( $rows_affected === false ) {

    error_log( 'Notification for Telegram - An error occurred while executing the plugin optimization query.' );

    } elseif ( $rows_affected === 0 ) {


    error_log( 'Notification for Telegram - No options were updated. Check the prefix and try again.' );
    } else {

    error_log( 'Notification for Telegram - We have optimized the database nftb_new_order_id_for_notification_ to make the Notification for Telegram plugin faster. The update modified ' . $rows_affected . ' records.' );


    }
    update_option( 'nftb_fix_1', '1', true);
    }
    • This reply was modified 1 month, 3 weeks ago by rainafarai.
Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.