From 98798af9d0733f6c1d3d28d4d99434a28ff73a44 Mon Sep 17 00:00:00 2001 From: K Adam White Date: Thu, 22 Aug 2024 13:18:41 -0400 Subject: [PATCH] Do not update_option for DB version on every request The install_db function is hooked into the plugins loaded action, but includes an `update_option` call which is fired even when the stored option DOES match. This is inefficient, and can cause unnecessary DB write load. It is especially problematic on some enterprise hosting where an UPDATE call causes all subsequent reads in a request to go through a Writer database instead of a read replica, overwhelming production DB servers. --- lib/WP_Auth0_DBManager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/WP_Auth0_DBManager.php b/lib/WP_Auth0_DBManager.php index 48382388..d31d2012 100644 --- a/lib/WP_Auth0_DBManager.php +++ b/lib/WP_Auth0_DBManager.php @@ -19,7 +19,11 @@ public function install_db($version_to_install = null) $current_ver = (int) get_site_option('auth0_db_version', 0); } - if (empty($current_ver) || $current_ver === AUTH0_DB_VERSION) { + if ($current_ver === AUTH0_DB_VERSION) { + return; + } + + if (empty($current_ver)) { update_option('auth0_db_version', AUTH0_DB_VERSION); return; }