1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- defined('GNUSOCIAL') || die();
- class PopularNoticeStream extends ScopingNoticeStream
- {
- public function __construct(Profile $scoped=null)
- {
- parent::__construct(
- new CachingNoticeStream(
- new RawPopularNoticeStream(),
- 'popular',
- false
- ),
- $scoped
- );
- }
- }
- class RawPopularNoticeStream extends NoticeStream
- {
- public function getNoticeIds($offset, $limit, $since_id, $max_id)
- {
- $weightexpr = common_sql_weight(
- 'modified',
- common_config('popular', 'dropoff')
- );
- $cutoff = sprintf(
- "modified > CURRENT_TIMESTAMP - INTERVAL '%d' SECOND",
- common_config('popular', 'cutoff')
- );
- $fave = new Fave();
- $fave->selectAdd();
- $fave->selectAdd('notice_id');
- $fave->selectAdd("{$weightexpr} AS weight");
- $fave->whereAdd($cutoff);
- $fave->groupBy('notice_id');
- $fave->orderBy('weight DESC');
- if (!is_null($offset)) {
- $fave->limit($offset, $limit);
- }
-
- $ids = array();
- if ($fave->find()) {
- while ($fave->fetch()) {
- $ids[] = $fave->notice_id;
- }
- }
- return $ids;
- }
- }
|