Slow query
-
Hi there,
You should avoid using
SELECT COUNT(*) FROM wp_aff_hits;
to create a unique string for hashing, like you’re doing in theaffiliates_record_hit
function. Usingmt_rand()
(or something similar) should be enough.$hash = hash( 'sha256', mt_rand(9, 99999) . $affiliate_id . $now );
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.