diff options
author | CiaranG <ciaran@ciarang.com> | 2009-03-04 15:32:26 +0000 |
---|---|---|
committer | CiaranG <ciaran@ciarang.com> | 2009-03-04 15:32:26 +0000 |
commit | 115519a5e7e84e57656c653918efb39ab4107fe9 (patch) | |
tree | 2c66758d4df65f8d9b76cc17a6893c662debdf16 /lib/popularnoticesection.php | |
parent | c02a2f189139bd3588b04e557239e243805aaeac (diff) |
PostgreSQL - made all 'weight' calculating SQL expressions compatible with both databases, and made some GROUP BY queries more explicit about the fields they are selecting, for the same reason.
Diffstat (limited to 'lib/popularnoticesection.php')
-rw-r--r-- | lib/popularnoticesection.php | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php index c7c7f0215..f7fb93554 100644 --- a/lib/popularnoticesection.php +++ b/lib/popularnoticesection.php @@ -48,10 +48,16 @@ class PopularNoticeSection extends NoticeSection { function getNotices() { - $qry = 'SELECT notice.*, '. - 'sum(exp(-(now() - fave.modified) / %s)) as weight ' . + if (common_config('db', 'type') == 'pgsql') { + $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))'; + } else { + $weightexpr='sum(exp(-(now() - fave.modified) / %s))'; + } + + $qry = 'SELECT notice.id, '. + $weightexpr . ' as weight ' . 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . - 'GROUP BY fave.notice_id ' . + 'GROUP BY notice.id ' . 'ORDER BY weight DESC'; $offset = 0; |