Permalink
Browse files

caching show tables

  • Loading branch information...
KellyLSB committed Apr 17, 2012
1 parent 9740b93 commit cc45a39b99b0d6b27c6b107083037348cf034137
Showing with 34 additions and 10 deletions.
  1. +8 −2 library/architect.php
  2. +8 −2 library/connection.php
  3. +9 −3 library/listobj.php
  4. +9 −3 library/model.php
View
@@ -170,9 +170,15 @@ public function __construct(Connection $dbh, $table, $config) {
}
protected function _exists($table = false) {
+ static $cache = array();
+
+ if(isset($cache[$table]))
+ return $cache[$table];
+
$table = $table ? $table : $this->table;
- if(!$this->dbh->query("SHOW TABLES LIKE '$table'")->row()) return false;
- else return true;
+ if(!$this->dbh->query("SHOW TABLES LIKE '$table'"))
+ return $cache[$table] = true;
+ else $cache[$table] = false;
}
protected function _compare() {
View
@@ -119,9 +119,15 @@ public function getConnectionTable($t1, $t2) {
* Checks to see if a table exists
*/
public function _exists($table = false) {
+ static $cache = array();
+
+ if(isset($cache[$table]))
+ return $cache[$table];
+
$table = $table ? $table : $this->table;
- if(!$this->query("SHOW TABLES LIKE '$table'")->row()) return false;
- else return true;
+ if(!$this->query("SHOW TABLES LIKE '$table'")->row())
+ return $cache[$table] = true;
+ else $cache[$table] = false;
}
/**
View
@@ -1025,9 +1025,15 @@ public function auto() {
* @author Kelly Becker
*/
private function _exists($table = false) {
- $table = $table ? $table : $this->_table;
- if(!e::sql($this->_connection)->query("SHOW TABLES LIKE '$table'")->row()) return false;
- else return true;
+ static $cache = array();
+
+ if(isset($cache[$table]))
+ return $cache[$table];
+
+ $table = $table ? $table : $this->table;
+ if(!e::sql($this->_connection)->query("SHOW TABLES LIKE '$table'")->row())
+ return $cache[$table] = true;
+ else $cache[$table] = false;
}
}
View
@@ -894,9 +894,15 @@ public function __call($func, $args) {
}
private function _exists($table = false) {
- $table = $table ? $table : $this->_table;
- if(!$this->_connection->query("SHOW TABLES LIKE '$table'")->row()) return false;
- else return true;
+ static $cache = array();
+
+ if(isset($cache[$table]))
+ return $cache[$table];
+
+ $table = $table ? $table : $this->table;
+ if(!$this->_connection->query("SHOW TABLES LIKE '$table'")->row())
+ return $cache[$table] = true;
+ else $cache[$table] = false;
}
}

0 comments on commit cc45a39

Please sign in to comment.