• Resolved valehero

    (@valehero)


    I want to disable and delete all old Transaction history.

    Now I use this code to debit credits and insert Transaction in DB:

    $transaction_id = woo_wallet()->wallet->debit( $userid, $serviceprice, $refid);
    do_action( 'woo_wallet_admin_adjust_balance', $transaction_id );
    $credits = woo_wallet()->wallet->get_wallet_balance($userid, 'edit');

    How can I debit the credits without inserting the Transaction in history?
    And how should I delete all the old Transaction history for users without effecting there current credits?

    Thank you so much for helping.

    • This topic was modified 5 years, 4 months ago by valehero.
    • This topic was modified 5 years, 4 months ago by valehero.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter valehero

    (@valehero)

    I need to disable and delete all old Transaction history cause now I have 30.000+ Transactions in all users history and it slows down my website by 6-7 seconds if I load the terra wallet pages.

    Now I have deleted all users Transaction history and terra wallet pages loads in less than 1 second.

    For now I came up with this code below, and I set it as Cron job to delete all Transaction history and update users credits:

    <?php
    	require_once("wp-config.php");
    	require_once("wp-includes/wp-db.php");
    
    	$users = get_users( array( 'fields' => array( 'ID' ) ) );
    	foreach($users as $key => $user_id){
    		$UID = $user_id->ID;
    		$meta = get_user_meta( $UID, '_current_woo_wallet_balance', true );
    		$terra = woo_wallet()->wallet->get_wallet_balance($UID, 'edit');
    		if ($meta > 0) {	
    			$wpdb->query( "DELETE FROM wp_woo_wallet_transactions WHERE user_id = '$UID'" );
    			$transaction_id = woo_wallet()->wallet->credit( $UID, $meta, 'Updated' );
    			do_action( 'woo_wallet_admin_adjust_balance', $transaction_id );
    			update_user_meta($UID, '_current_woo_wallet_balance', $meta);
    		}		
    	}
    ?>

    Is there any better way to do this?
    Is there a way to disable Transaction history so it wont grow so big and slow down the entire website?

    Sample: Show only last 10 or last 100 Transactions and delete all before that?

    Important:
    * I noticed memory usage went downs 20% after deleting all Transactions.
    * CPU usage went down by 15% after deleting the all Transaction history.

    • This reply was modified 5 years, 4 months ago by valehero.
    • This reply was modified 5 years, 4 months ago by valehero.
    • This reply was modified 5 years, 4 months ago by valehero.
    • This reply was modified 5 years, 4 months ago by valehero.
    Plugin Author Subrata Mal

    (@subratamal)

    Hi @valehero

    We agree with you and the code you are using is ok as Cron job.

    Hi

    Can you please tell me where this code is inserted? In wp-config?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to disable and delete Transaction history without effecting User Credits?’ is closed to new replies.