return $i;
} else {
$i = DB_DataObject::factory($cls);
- if (empty($i)) {
+ if (empty($i) || PEAR::isError($i)) {
return false;
}
foreach ($kv as $k => $v) {
}
static function memcache() {
- return common_memcache();
+ return Cache::instance();
}
static function cacheKey($cls, $k, $v) {
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) {
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);
+ }
}
}
$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) {
}
$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;
}
}
}
}
+ // Needed to make timestamp values usefully comparable.
+ if (common_config('db', 'type') == 'mysql') {
+ parent::_query("set time_zone='+0:00'");
+ }
}
return $result;
$keyPart = vsprintf($format, $args);
- $cacheKey = common_cache_key($keyPart);
+ $cacheKey = Cache::key($keyPart);
return $c->delete($cacheKey);
}
return false;
}
- $cacheKey = common_cache_key($keyPart);
+ $cacheKey = Cache::key($keyPart);
return $c->get($cacheKey);
}
return false;
}
- $cacheKey = common_cache_key($keyPart);
+ $cacheKey = Cache::key($keyPart);
return $c->set($cacheKey, $value, $flag, $expiry);
}
return $vstr;
}
}
-