Skip to content

Commit

Permalink
Cache SHOW table statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Dec 6, 2023
1 parent d918a3c commit 4725be5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion source/php/EventArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class EventArchive
{
private $eventPostType = 'event';
private $dbTable;
private $db;

public function __construct()
{
Expand All @@ -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);
}

Expand All @@ -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();
Expand Down

0 comments on commit 4725be5

Please sign in to comment.