forked from GNUsocial/gnu-social
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -10,8 +10,8 @@ class Queue_item extends Memcached_DataObject
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'queue_item'; // table name
|
||||
public $notice_id; // int(4) primary_key not_null
|
||||
public $transport; // varchar(8) primary_key not_null
|
||||
public $id; // int(4) primary_key not_null
|
||||
public $frame; // blob not_null
|
||||
public $created; // datetime() not_null
|
||||
public $claimed; // datetime()
|
||||
|
||||
@@ -22,14 +22,21 @@ class Queue_item extends Memcached_DataObject
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
|
||||
function sequenceKey()
|
||||
{ return array(false, false); }
|
||||
|
||||
static function top($transport=null) {
|
||||
/**
|
||||
* @param mixed $transports name of a single queue or array of queues to pull from
|
||||
* If not specified, checks all queues in the system.
|
||||
*/
|
||||
static function top($transports=null) {
|
||||
|
||||
$qi = new Queue_item();
|
||||
if ($transport) {
|
||||
$qi->transport = $transport;
|
||||
if ($transports) {
|
||||
if (is_array($transports)) {
|
||||
// @fixme use safer escaping
|
||||
$list = implode("','", array_map('addslashes', $transports));
|
||||
$qi->whereAdd("transport in ('$list')");
|
||||
} else {
|
||||
$qi->transport = $transports;
|
||||
}
|
||||
}
|
||||
$qi->orderBy('created');
|
||||
$qi->whereAdd('claimed is null');
|
||||
@@ -42,7 +49,7 @@ class Queue_item extends Memcached_DataObject
|
||||
# XXX: potential race condition
|
||||
# can we force it to only update if claimed is still null
|
||||
# (or old)?
|
||||
common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id .
|
||||
common_log(LOG_INFO, 'claiming queue item id = ' . $qi->id .
|
||||
' for transport ' . $qi->transport);
|
||||
$orig = clone($qi);
|
||||
$qi->claimed = common_sql_now();
|
||||
@@ -57,9 +64,4 @@ class Queue_item extends Memcached_DataObject
|
||||
$qi = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
function pkeyGet($kv)
|
||||
{
|
||||
return Memcached_DataObject::pkeyGet('Queue_item', $kv);
|
||||
}
|
||||
}
|
||||
|
@@ -396,14 +396,14 @@ tagged = K
|
||||
tag = K
|
||||
|
||||
[queue_item]
|
||||
notice_id = 129
|
||||
id = 129
|
||||
frame = 66
|
||||
transport = 130
|
||||
created = 142
|
||||
claimed = 14
|
||||
|
||||
[queue_item__keys]
|
||||
notice_id = K
|
||||
transport = K
|
||||
id = K
|
||||
|
||||
[related_group]
|
||||
group_id = 129
|
||||
|
Reference in New Issue
Block a user