improved performance of getTableDescriptionFromCache
authorLars Kneschke <l.kneschke@metaways.de>
Sat, 20 Dec 2014 22:16:08 +0000 (23:16 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 29 Dec 2014 09:19:49 +0000 (10:19 +0100)
- call Zend_Db::describeTable() without the overhead of Zend_Db_Table

Change-Id: I584152a1c77b1552e45d78bb048dbefe782eec4e
Reviewed-on: http://gerrit.tine20.com/customers/1479
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Db/Table.php

index 5ceeda1..3167564 100644 (file)
  */
 class Tinebase_Db_Table extends Zend_Db_Table_Abstract
 {
+    protected static $_classCache = array(
+        'getTableDescriptionFromCache' => array()
+    );
+    
     /**
      * wrapper around Zend_Db_Table_Abstract::fetchAll
      *
@@ -82,19 +86,35 @@ class Tinebase_Db_Table extends Zend_Db_Table_Abstract
         if ($db === NULL) {
             $db = Tinebase_Core::getDb();
         }
-        try {
-            $config = array(
-                'name' => $tableName,
-                'db'   => $db
-            );
-            $tableDescription = new Tinebase_Db_Table($config);
-            $tableInfo = $tableDescription->info();
-            $result = $tableInfo['metadata'];
-        } catch (Zend_Db_Table_Exception $zdte) {
-            if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
-                . ' Could not fetch schema from cache: ' . $zdte->getMessage());
+        
+        $cache = Tinebase_Core::getCache();
+        $dbConfig = $db->getConfig();
+        
+        $classCacheId = md5($dbConfig['host'] . $dbConfig['dbname'] . $tableName);
+        
+        if (isset(self::$_classCache[__FUNCTION__][$classCacheId])) {
+            return self::$_classCache[__FUNCTION__][$classCacheId];
+        }
+        
+        $cacheId = __FUNCTION__ . $classCacheId;
+        
+        #if ($result = apc_fetch($cacheId)) {
+        #    self::$_classCache[__FUNCTION__][$classCacheId] = $result;
+        #    
+        #    return $result;
+        #}
+        
+        $result = $cache->load($cacheId);
+        
+        if (!$result) {
             $result = $db->describeTable($tableName);
+            
+            $cache->save($result, $cacheId);
+            #apc_store($cacheId, $result, 60);
+            self::$_classCache[__FUNCTION__][$classCacheId] = $result;
         }
+        
+        
         return $result;
     }
 }