X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftag.php;h=75bf6c8bfb76267ed56850926e754f689ecfd4dc;hb=85b9e58e535d44f5973fe14f888dc19f25bcaddd;hp=1042513d5a1a42faee8b5ddf5e54736e3e583e6e;hpb=37c5e8ca3c2d77fc3e1836fd76d7462e33f1668e;p=quix0rs-gnu-social.git diff --git a/actions/tag.php b/actions/tag.php index 1042513d5a..75bf6c8bfb 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -88,8 +88,21 @@ class TagAction extends StreamAction { { # This should probably be cached rather than recalculated $tags = DB_DataObject::factory('Notice_tag'); + + #Need to clear the selection and then only re-add the field + #we are grouping by, otherwise it's not a valid 'group by' + #even though MySQL seems to let it slide... + $tags->selectAdd(); + $tags->selectAdd('tag'); + + #Add the aggregated columns... $tags->selectAdd('max(notice_id) as last_notice_id'); - $tags->selectAdd(sprintf('sum(exp(-(now() - created)/%f)) as weight', common_config('tag', 'dropoff'))); + 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'))); $tags->groupBy('tag'); $tags->orderBy('weight DESC'); @@ -146,33 +159,20 @@ class TagAction extends StreamAction { function show_notices($tag) { - $tags = DB_DataObject::factory('Notice_tag'); - - $tags->tag = $tag; - - $tags->orderBy('created DESC'); - + $cnt = 0; + $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - $tags->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); + $notice = Notice_tag::getStream($tag, (($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); - $cnt = $tags->find(); - - if ($cnt > 0) { + if ($notice) { common_element_start('ul', array('id' => 'notices')); - for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) { - if ($tags->fetch()) { - $notice = new Notice(); - $notice->id = $tags->notice_id; - $result = $notice->find(true); - if (!$result) { - continue; - } - $this->show_notice($notice); - } else { - // shouldn't happen! + while ($notice->fetch()) { + $cnt++; + if ($cnt > NOTICES_PER_PAGE) { break; } + $this->show_notice($notice); } common_element_end('ul'); }