• Hi there,

    You should avoid using SELECT COUNT(*) FROM wp_aff_hits; to create a unique string for hashing, like you’re doing in the affiliates_record_hit function. Using mt_rand() (or something similar) should be enough.

    $hash     = hash( 'sha256', mt_rand(9, 99999) . $affiliate_id . $now );

    https://github.com/itthinx/affiliates/blob/cc32dab25b1d46adc309fb6330fe920a42922970/lib/core/wp-init.php#L1167C1-L1167C67

    If the table gets large, the SQL query can become really slow. Check out this example from the MySQL slow query log:

    # Time: 240814  7:09:01
    # User@Host: redacted[redacted] @ localhost []
    # Thread_id: 43156 Schema: redacted QC_hit: No
    # Query_time: 1.438982 Lock_time: 0.000051 Rows_sent: 1 Rows_examined: 7044052
    # Rows_affected: 0 Bytes_sent: 69
    SET timestamp=1723612141;
    SELECT COUNT(*) FROM wp_aff_hits;

    In my case, it takes over a second every single time.

    Hope this helps!

    PS: The issue is present in the Pro version as well.

  • You must be logged in to reply to this topic.