Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log entry insertions can be extremely slow due to unique slug lookup #2703

Open
boonebgorges opened this issue Nov 18, 2024 · 0 comments
Open

Comments

@boonebgorges
Copy link

IF YOU DO NOT FOLLOW THIS TEMPLATE, YOUR ISSUE MAY BE CLOSED!!

Please provide the following information when creating your issues:

Site Info

WordPress Version: 6.6.2
QSM Version: 9.1.3
Browser: all

General description

When QMN_Log_Manager::insert_log() writes items to the posts table, it can dramatically slow down the site. I saw this specifically in the context of a failed database update (which I'll describe in a separate ticket). The plugin was trying to log the failure to run the utf8mb4 conversions introduced in 9.0.1:

$mlwQuizMasterNext->log_manager->add( 'Error updating column charset utf8mb4_unicode_ci', "Tried $query but got {$wpdb->last_error}.", 0, 'error' );

But the upgrade had failed a number of times before, meaning that there were already hundreds of identical log entries. When calling wp_insert_post()

public function insert_log( $log_data = array(), $log_meta = null ) {
without passing a post_name, WP used wp_unique_post_slug() to build a slug based on the post title. But it had to try hundreds of different numerical suffixes before finding a unique one.

Expected behavior

One of two things:

  1. Don't insert hundreds of duplicate log entries. In some cases, dupes are helpful. But for an upgrade routine that loads on every 'admin_init' and tries to run the same database upgrade routine, I'd suggest that the duplicates are not useful.
  2. Pass a known-unique slug to wp_insert_post(). Something like 'qsm-log-entry-' . time() would be enough to avoid the costly lookups.

Actual behavior

Many queries are performed

Steps to reproduce the behavior

Insert a bunch of identical log entries, then monitor SQL queries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant