From 4725be550414c7a7f483a9d506e9705857ddf56b Mon Sep 17 00:00:00 2001 From: Sebastian Thulin Date: Wed, 6 Dec 2023 11:34:29 +0100 Subject: [PATCH] Cache SHOW table statement --- source/php/EventArchive.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/php/EventArchive.php b/source/php/EventArchive.php index 67120472..b4313ea6 100644 --- a/source/php/EventArchive.php +++ b/source/php/EventArchive.php @@ -6,6 +6,7 @@ class EventArchive { private $eventPostType = 'event'; private $dbTable; + private $db; public function __construct() { @@ -15,7 +16,7 @@ public function __construct() $this->dbTable = $wpdb->prefix . "integrate_occasions"; //Run functions if table exists - if ($this->db->get_var("SHOW TABLES LIKE '" . $this->dbTable . "'") !== null) { + if($this->occasionsTableExist()) { add_action('pre_get_posts', array($this, 'filterEvents'), 100); } @@ -26,6 +27,17 @@ public function __construct() add_filter('Municipio/Archive/getTaxonomyFilters/taxonomies', [$this, 'taxonomyFilters'], 999, 2); } + private function occasionsTableExist() { + if (wp_cache_get($this->dbTable) !== false) { + return true; + } + if ($this->db->get_var("SHOW TABLES LIKE '" . $this->dbTable . "'") !== null) { + wp_cache_set($this->dbTable, true); + return true; + } + return false; + } + public function showFilter($enabledFilters) { $current = get_queried_object();