summaryrefslogtreecommitdiff
path: root/classes/Memcached_DataObject.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-01-22 14:18:21 -0500
committerEvan Prodromou <evan@status.net>2010-01-22 14:18:21 -0500
commit29d83c8ca94201cb010b5aef564df78ab868ea0c (patch)
tree8bc66e2fc03865e287a4c1907e766d6b4311c832 /classes/Memcached_DataObject.php
parent104d300799c0817bdbe893f08fd9b46d37a75a80 (diff)
parent0e852def6ae5aa529cca0aef1187152fb5a880be (diff)
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
Diffstat (limited to 'classes/Memcached_DataObject.php')
-rw-r--r--classes/Memcached_DataObject.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 6ddef4816..33645a3e8 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -313,6 +313,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