Performance issue on user_login() method hooked on “wp_login”
-
Hello,
Im using WP 6.4.1 and BNFW 1.9.3, Debian Nginx PHP 8.1, custom Sage 9 theme. This is a Woocommerce store with thousands of products. So I have thousands of posts, and millions of post_meta. Also note that I’m using WP Index for MySQL.
I found a performance issue using your plugin. The issue is related to the
user_login()
hooked on thewp_login
action (bnfw.php line 200
andbnfw.php line 1080
).I’m using a custom authentication flow that calls
do_action('wp_login'...)
at some point. Your plugin has a method hooked on this action. BNFW calls$this->notifier->get_notifications( 'user-login' )
that trigger’s a long SQL request on the database to find BNFW notifications. Note that I don’t have any “on-login” notification enabled, but I assume the plugin must check that anyway.I debugged the entire login process and
wp_login
hooked methods, until I found your method, which was de culprit (among dozens of other hooked actions onwp_login
.The SQL request produced takes 56 seconds to run on my server:
Query needs to create temporary table to run:
I was able to remove your plugin’s hooked method. But it certainly means “disabling” the “on-login bnfw notifications”
add_action( 'plugins_loaded', 'bnfw_remove_login_plugin_filter' ); add_action( 'init', 'bnfw_remove_login_plugin_filter', 200 ); add_action( 'wp_login', function ( $user_login, $user ) { bnfw_remove_login_plugin_filter(); return $user_login; }, 1, 2 ); function bnfw_remove_login_plugin_filter() { if(class_exists( 'BNFW', false )) { $instance = \BNFW::factory(); remove_action( 'wp_login', array( $instance, 'user_login' ), 10 ); remove_action( 'wp_login', array( 'BNFW', 'user_login' ), 10 ); } }
I believe I could also use an Object Cache (eg: WP Redis) plugin to cache this request. I also fear that other BNFW notification triggers could produce the same kind of queries.
Debugging the SQL Query, it seems that the huge delays come from the
GROUP BY wp_posts.ID
. Removing the group_by makes the query less than 1s (from 60s to 1s removing the group_by).From more tests on the WP_Query args generated by your method, it all seems pretty “classical”, and the GROUP_BY is added by WP. Idk what i could do to optimise this.
I believe that it’s related to multiple INNER JOINs on same table. Found this also this
FIY
Thank you.
- The topic ‘Performance issue on user_login() method hooked on “wp_login”’ is closed to new replies.