diff options
author | Brion Vibber <brion@pobox.com> | 2010-01-21 16:33:11 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-01-21 16:33:11 -0800 |
commit | c9c7bb3234f8ede65c328ecf9f713b189a81faad (patch) | |
tree | 5834925a7ad38aad43af252f949cfd836fad9c4d /classes | |
parent | dcba61332223cfc875b355f6a5f4d2e574dd55b2 (diff) | |
parent | 4b0f953ccf7435d6ebe4a674953f62af36cc978b (diff) |
Merge commit 'origin/testing' into 0.9.x
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Memcached_DataObject.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 4ecab9db6..6ceb59e8b 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -315,6 +315,39 @@ class Memcached_DataObject extends DB_DataObject return new ArrayWrapper($cached); } + /** + * sends query to database - this is the private one that must work + * - internal functions use this rather than $this->query() + * + * Overridden to do logging. + * + * @param string $string + * @access private + * @return mixed none or PEAR_Error + */ + function _query($string) + { + $start = microtime(true); + $result = parent::_query($string); + $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)); + } + return $result; + } + + // Sanitize a query for logging + // @fixme don't trim spaces in string literals + function sanitizeQuery($string) + { + $string = preg_replace('/\s+/', ' ', $string); + $string = trim($string); + return $string; + } + // We overload so that 'SET NAMES "utf8"' is called for // each connection |