Poorly Performing Code in Analytics/Data Collector
-
Hello,
Thewp-content/plugins/embedpress/EmbedPress/Includes/Classes/Analytics/Data_Collector.phpcontains this code snippet:// Shortcode: posts containing [embedpress*] shortcodes
$shortcode_count = (int) $wpdb->get_var(
"SELECT COUNT(*) FROM {$wpdb->posts} p
WHERE {$status_condition} {$post_type_condition}
AND (
p.post_content LIKE '%[embedpress %' OR
p.post_content LIKE '%[embedpress]%' OR
p.post_content LIKE '%[embedpress_pdf %' OR
p.post_content LIKE '%[embedpress_document %' OR
p.post_content LIKE '%[embedpress_calendar %'
)"
);…which generates the following SQL query:
SELECT COUNT(*)
FROM wp_posts p
WHERE p.post_status IN ('publish','draft','private','future')
AND p.post_type IN ('post','page','product','event','portfolio')
AND (
p.post_content LIKE '%[embedpress %' OR
p.post_content LIKE '%[embedpress]%' OR
p.post_content LIKE '%[embedpress_pdf %' OR
p.post_content LIKE '%[embedpress_document %' OR
p.post_content LIKE '%[embedpress_calendar %'
)Because of the five
LIKE '%…%‘ conditions on post_content, the database cannot make effective use of a normal index; as a result, the query essentially scans through very large portions ofwp_posts.This SQL query takes about 1 minute to run in our WordPress installation (with > 100k posts), which is far too long and needs to be fixed urgently.
Best regards,
BenThe page I need help with: [log in to see the link]
You must be logged in to reply to this topic.