forked from GNUsocial/gnu-social
Merge branch 'master' of git@gitorious.org:statusnet/mainline
This commit is contained in:
commit
31585453fc
@ -185,11 +185,7 @@ class FavoritedAction extends Action
|
||||
|
||||
function showContent()
|
||||
{
|
||||
if (common_config('db', 'type') == 'pgsql') {
|
||||
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
|
||||
} else {
|
||||
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
|
||||
}
|
||||
$weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
|
||||
|
||||
$qry = 'SELECT notice.*, '.
|
||||
$weightexpr . ' as weight ' .
|
||||
@ -207,7 +203,7 @@ class FavoritedAction extends Action
|
||||
}
|
||||
|
||||
$notice = Memcached_DataObject::cachedQuery('Notice',
|
||||
sprintf($qry, common_config('popular', 'dropoff')),
|
||||
$qry,
|
||||
600);
|
||||
|
||||
$nl = new NoticeList($notice, $this);
|
||||
|
@ -105,12 +105,8 @@ class PublictagcloudAction extends Action
|
||||
|
||||
#Add the aggregated columns...
|
||||
$tags->selectAdd('max(notice_id) as last_notice_id');
|
||||
if(common_config('db','type')=='pgsql') {
|
||||
$calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight';
|
||||
} else {
|
||||
$calc='sum(exp(-(now() - created)/%s)) as weight';
|
||||
}
|
||||
$tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff')));
|
||||
$calc = common_sql_weight('created', common_config('tag', 'dropoff'));
|
||||
$tags->selectAdd($calc . ' as weight');
|
||||
$tags->groupBy('tag');
|
||||
$tags->orderBy('weight DESC');
|
||||
|
||||
@ -136,7 +132,12 @@ class PublictagcloudAction extends Action
|
||||
$this->elementStart('dd');
|
||||
$this->elementStart('ul', 'tags xoxo tag-cloud');
|
||||
foreach ($tw as $tag => $weight) {
|
||||
$this->showTag($tag, $weight, $weight/$sum);
|
||||
if ($sum) {
|
||||
$weightedSum = $weight/$sum;
|
||||
} else {
|
||||
$weightedSum = 0.5;
|
||||
}
|
||||
$this->showTag($tag, $weight, $weightedSum);
|
||||
}
|
||||
$this->elementEnd('ul');
|
||||
$this->elementEnd('dd');
|
||||
|
@ -23,6 +23,65 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
class Memcached_DataObject extends DB_DataObject
|
||||
{
|
||||
/**
|
||||
* Destructor to free global memory resources associated with
|
||||
* this data object when it's unset or goes out of scope.
|
||||
* DB_DataObject doesn't do this yet by itself.
|
||||
*/
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
$this->free();
|
||||
if (method_exists('DB_DataObject', '__destruct')) {
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function called at serialize() time.
|
||||
*
|
||||
* We use this to drop a couple process-specific references
|
||||
* from DB_DataObject which can cause trouble in future
|
||||
* processes.
|
||||
*
|
||||
* @return array of variable names to include in serialization.
|
||||
*/
|
||||
function __sleep()
|
||||
{
|
||||
$vars = array_keys(get_object_vars($this));
|
||||
$skip = array('_DB_resultid', '_link_loaded');
|
||||
return array_diff($vars, $skip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function called at unserialize() time.
|
||||
*
|
||||
* Clean out some process-specific variables which might
|
||||
* be floating around from a previous process's cached
|
||||
* objects.
|
||||
*
|
||||
* Old cached objects may still have them.
|
||||
*/
|
||||
function __wakeup()
|
||||
{
|
||||
// Refers to global state info from a previous process.
|
||||
// Clear this out so we don't accidentally break global
|
||||
// state in *this* process.
|
||||
$this->_DB_resultid = null;
|
||||
|
||||
// We don't have any local DBO refs, so clear these out.
|
||||
$this->_link_loaded = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for DB_DataObject's static lookup using memcached
|
||||
* as backing instead of an in-process cache array.
|
||||
*
|
||||
* @param string $cls classname of object type to load
|
||||
* @param mixed $k key field name, or value for primary key
|
||||
* @param mixed $v key field value, or leave out for primary key lookup
|
||||
* @return mixed Memcached_DataObject subtype or false
|
||||
*/
|
||||
function &staticGet($cls, $k, $v=null)
|
||||
{
|
||||
if (is_null($v)) {
|
||||
|
@ -58,11 +58,7 @@ class GroupTagCloudSection extends TagCloudSection
|
||||
|
||||
function getTags()
|
||||
{
|
||||
if (common_config('db', 'type') == 'pgsql') {
|
||||
$weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
|
||||
} else {
|
||||
$weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
|
||||
}
|
||||
$weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
|
||||
|
||||
$names = $this->group->getAliases();
|
||||
|
||||
@ -99,7 +95,6 @@ class GroupTagCloudSection extends TagCloudSection
|
||||
|
||||
$tag = Memcached_DataObject::cachedQuery('Notice_tag',
|
||||
sprintf($qry,
|
||||
common_config('tag', 'dropoff'),
|
||||
$this->group->id,
|
||||
$namestring),
|
||||
3600);
|
||||
|
@ -58,11 +58,7 @@ class PersonalTagCloudSection extends TagCloudSection
|
||||
|
||||
function getTags()
|
||||
{
|
||||
if (common_config('db', 'type') == 'pgsql') {
|
||||
$weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
|
||||
} else {
|
||||
$weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
|
||||
}
|
||||
$weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
|
||||
|
||||
$qry = 'SELECT notice_tag.tag, '.
|
||||
$weightexpr . ' as weight ' .
|
||||
@ -83,7 +79,6 @@ class PersonalTagCloudSection extends TagCloudSection
|
||||
|
||||
$tag = Memcached_DataObject::cachedQuery('Notice_tag',
|
||||
sprintf($qry,
|
||||
common_config('tag', 'dropoff'),
|
||||
$this->user->id),
|
||||
3600);
|
||||
return $tag;
|
||||
|
@ -48,17 +48,17 @@ class PopularNoticeSection extends NoticeSection
|
||||
{
|
||||
function getNotices()
|
||||
{
|
||||
// @fixme there should be a common func for this
|
||||
if (common_config('db', 'type') == 'pgsql') {
|
||||
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
|
||||
if (!empty($this->out->tag)) {
|
||||
$tag = pg_escape_string($this->out->tag);
|
||||
}
|
||||
} else {
|
||||
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
|
||||
if (!empty($this->out->tag)) {
|
||||
$tag = mysql_escape_string($this->out->tag);
|
||||
}
|
||||
}
|
||||
$weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
|
||||
$qry = "SELECT notice.*, $weightexpr as weight ";
|
||||
if(isset($tag)) {
|
||||
$qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' .
|
||||
@ -78,7 +78,7 @@ class PopularNoticeSection extends NoticeSection
|
||||
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
|
||||
|
||||
$notice = Memcached_DataObject::cachedQuery('Notice',
|
||||
sprintf($qry, common_config('popular', 'dropoff')),
|
||||
$qry,
|
||||
1200);
|
||||
return $notice;
|
||||
}
|
||||
|
20
lib/util.php
20
lib/util.php
@ -908,6 +908,26 @@ function common_sql_date($datetime)
|
||||
return strftime('%Y-%m-%d %H:%M:%S', $datetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an SQL fragment to calculate an age-based weight from a given
|
||||
* timestamp or datetime column.
|
||||
*
|
||||
* @param string $column name of field we're comparing against current time
|
||||
* @param integer $dropoff divisor for age in seconds before exponentiation
|
||||
* @return string SQL fragment
|
||||
*/
|
||||
function common_sql_weight($column, $dropoff)
|
||||
{
|
||||
if (common_config('db', 'type') == 'pgsql') {
|
||||
// PostgreSQL doesn't support timestampdiff function.
|
||||
// @fixme will this use the right time zone?
|
||||
// @fixme does this handle cross-year subtraction correctly?
|
||||
return "sum(exp(-extract(epoch from (now() - $column)) / $dropoff))";
|
||||
} else {
|
||||
return "sum(exp(timestampdiff(second, utc_timestamp(), $column) / $dropoff))";
|
||||
}
|
||||
}
|
||||
|
||||
function common_redirect($url, $code=307)
|
||||
{
|
||||
static $status = array(301 => "Moved Permanently",
|
||||
|
Loading…
Reference in New Issue
Block a user