X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FMemcached_DataObject.php;h=c361ba878313f0ddbf51ab0d0125d76ea6e5c6fe;hb=3ba4258f9e13d6ba84dd21197782303ac26b28fd;hp=0f1ed04892a61335b7913177e385bcd32bfd56a3;hpb=bee50840728ca8af99e988bcce71876849ba61d3;p=quix0rs-gnu-social.git diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 0f1ed04892..c361ba8783 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -34,7 +34,7 @@ class Memcached_DataObject extends Safe_DataObject { if (is_null($v)) { $v = $k; - # XXX: HACK! + // XXX: HACK! $i = new $cls; $keys = $i->keys(); $k = $keys[0]; @@ -74,7 +74,7 @@ class Memcached_DataObject extends Safe_DataObject return $i; } else { $i = DB_DataObject::factory($cls); - if (empty($i)) { + if (empty($i) || PEAR::isError($i)) { return false; } foreach ($kv as $k => $v) { @@ -124,7 +124,7 @@ class Memcached_DataObject extends Safe_DataObject } static function memcache() { - return common_memcache(); + return Cache::instance(); } static function cacheKey($cls, $k, $v) { @@ -134,7 +134,7 @@ class Memcached_DataObject extends Safe_DataObject str_replace("\n", " ", $e->getTraceAsString())); } $vstr = self::valueString($v); - return common_cache_key(strtolower($cls).':'.$k.':'.$vstr); + return Cache::key(strtolower($cls).':'.$k.':'.$vstr); } static function getcached($cls, $k, $v) { @@ -189,11 +189,11 @@ class Memcached_DataObject extends Safe_DataObject str_replace("\n", " ", $e->getTraceAsString())); return false; } else { - $keys = $this->_allCacheKeys(); + $keys = $this->_allCacheKeys(); - foreach ($keys as $key) { - $c->set($key, $this); - } + foreach ($keys as $key) { + $c->set($key, $this); + } } } @@ -273,24 +273,23 @@ class Memcached_DataObject extends Safe_DataObject function getSearchEngine($table) { require_once INSTALLDIR.'/lib/search_engines.php'; - static $search_engine; - if (!isset($search_engine)) { - if (Event::handle('GetSearchEngine', array($this, $table, &$search_engine))) { - if ('mysql' === common_config('db', 'type')) { - $type = common_config('search', 'type'); - if ($type == 'like') { - $search_engine = new MySQLLikeSearch($this, $table); - } else if ($type == 'fulltext') { - $search_engine = new MySQLSearch($this, $table); - } else { - // Low level exception. No need for i18n as discussed with Brion. - throw new ServerException('Unknown search type: ' . $type); - } + + if (Event::handle('GetSearchEngine', array($this, $table, &$search_engine))) { + if ('mysql' === common_config('db', 'type')) { + $type = common_config('search', 'type'); + if ($type == 'like') { + $search_engine = new MySQLLikeSearch($this, $table); + } else if ($type == 'fulltext') { + $search_engine = new MySQLSearch($this, $table); } else { - $search_engine = new PGSearch($this, $table); + // Low level exception. No need for i18n as discussed with Brion. + throw new ServerException('Unknown search type: ' . $type); } + } else { + $search_engine = new PGSearch($this, $table); } } + return $search_engine; } @@ -302,8 +301,8 @@ class Memcached_DataObject extends Safe_DataObject $inst->query($qry); return $inst; } - $key_part = common_keyize($cls).':'.md5($qry); - $ckey = common_cache_key($key_part); + $key_part = Cache::keyize($cls).':'.md5($qry); + $ckey = Cache::key($key_part); $stored = $c->get($ckey); if ($stored !== false) { @@ -338,13 +337,32 @@ class Memcached_DataObject extends Safe_DataObject } $start = microtime(true); - $result = parent::_query($string); + $fail = false; + $result = null; + if (Event::handle('StartDBQuery', array($this, $string, &$result))) { + common_perf_counter('query', $string); + try { + $result = parent::_query($string); + } catch (Exception $e) { + $fail = $e; + } + Event::handle('EndDBQuery', array($this, $string, &$result)); + } $delta = microtime(true) - $start; $limit = common_config('db', 'log_slow_queries'); if (($limit > 0 && $delta >= $limit) || common_config('db', 'log_queries')) { $clean = $this->sanitizeQuery($string); - common_log(LOG_DEBUG, sprintf("DB query (%0.3fs): %s", $delta, $clean)); + if ($fail) { + $msg = sprintf("FAILED DB query (%0.3fs): %s - %s", $delta, $fail->getMessage(), $clean); + } else { + $msg = sprintf("DB query (%0.3fs): %s", $delta, $clean); + } + common_log(LOG_DEBUG, $msg); + } + + if ($fail) { + throw $fail; } return $result; } @@ -476,6 +494,10 @@ class Memcached_DataObject extends Safe_DataObject } } } + // Needed to make timestamp values usefully comparable. + if (common_config('db', 'type') == 'mysql') { + parent::_query("set time_zone='+0:00'"); + } } return $result; @@ -550,7 +572,7 @@ class Memcached_DataObject extends Safe_DataObject $keyPart = vsprintf($format, $args); - $cacheKey = common_cache_key($keyPart); + $cacheKey = Cache::key($keyPart); return $c->delete($cacheKey); } @@ -592,7 +614,7 @@ class Memcached_DataObject extends Safe_DataObject return false; } - $cacheKey = common_cache_key($keyPart); + $cacheKey = Cache::key($keyPart); return $c->get($cacheKey); } @@ -605,7 +627,7 @@ class Memcached_DataObject extends Safe_DataObject return false; } - $cacheKey = common_cache_key($keyPart); + $cacheKey = Cache::key($keyPart); return $c->set($cacheKey, $value, $flag, $expiry); } @@ -637,4 +659,3 @@ class Memcached_DataObject extends Safe_DataObject return $vstr; } } -