summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@status.net>2010-01-04 13:01:17 -0800
committerBrion Vibber <brion@status.net>2010-01-04 13:01:17 -0800
commitaf95005bc481d6f8f84a780bdc062426e22f3a03 (patch)
tree3ff7380f81ff918a0b42d4c4a55dfa3a41412053 /actions
parentd32fb7c7c40e3d5fa67496d5df0574fc9c2e0151 (diff)
Ticket 2141: bugs with weighted popularity lists across year boundary.
Consolidated several separate implementations of the same weighting algorithm into common_sql_weight() and fixed some bugs... For MySQL, now using timestampdiff() instead of subtraction for the comparison, so we get sane results when the year doesn't match, and utc_timestamp() rather than now() so we don't get negative ages for recent items with local server timezone. Unknown whether the same problems affect PostgreSQL, but note that it lacks the timestampdiff() SQL function.
Diffstat (limited to 'actions')
-rw-r--r--actions/favorited.php8
-rw-r--r--actions/publictagcloud.php15
2 files changed, 10 insertions, 13 deletions
diff --git a/actions/favorited.php b/actions/favorited.php
index 150b67b0b..9ffa5b844 100644
--- a/actions/favorited.php
+++ b/actions/favorited.php
@@ -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);
diff --git a/actions/publictagcloud.php b/actions/publictagcloud.php
index e7f6ee36c..9e4478dbb 100644
--- a/actions/publictagcloud.php
+++ b/actions/publictagcloud.php
@@ -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');