mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update PublicTimelineService
This commit is contained in:
parent
562726bc17
commit
918016a5ad
2 changed files with 34 additions and 10 deletions
|
@ -18,18 +18,41 @@ class PublicTimelineService {
|
||||||
if($stop > 100) {
|
if($stop > 100) {
|
||||||
$stop = 100;
|
$stop = 100;
|
||||||
}
|
}
|
||||||
$tl = [];
|
|
||||||
$keys = Redis::zrevrange(self::CACHE_KEY, $start, $stop);
|
return Redis::zrevrange(self::CACHE_KEY, $start, $stop);
|
||||||
foreach($keys as $key) {
|
|
||||||
array_push($tl, StatusService::get($key));
|
|
||||||
}
|
}
|
||||||
return $tl;
|
|
||||||
|
public static function getRankedMaxId($start = null, $limit = 10)
|
||||||
|
{
|
||||||
|
if(!$start) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_keys(Redis::zrevrangebyscore(self::CACHE_KEY, $start, '-inf', [
|
||||||
|
'withscores' => true,
|
||||||
|
'limit' => [1, $limit]
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRankedMinId($end = null, $limit = 10)
|
||||||
|
{
|
||||||
|
if(!$end) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_keys(Redis::zrevrangebyscore(self::CACHE_KEY, '+inf', $end, [
|
||||||
|
'withscores' => true,
|
||||||
|
'limit' => [0, $limit]
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add($val)
|
public static function add($val)
|
||||||
{
|
{
|
||||||
// return Redis::zadd(self::CACHE_KEY, $val, $val);
|
if(self::count() > 400) {
|
||||||
return;
|
Redis::zpopmin(self::CACHE_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Redis::zadd(self::CACHE_KEY, $val, $val);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function rem($val)
|
public static function rem($val)
|
||||||
|
@ -44,7 +67,7 @@ class PublicTimelineService {
|
||||||
|
|
||||||
public static function count()
|
public static function count()
|
||||||
{
|
{
|
||||||
return Redis::zcount(self::CACHE_KEY, '-inf', '+inf');
|
return Redis::zcard(self::CACHE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function warmCache($force = false, $limit = 100)
|
public static function warmCache($force = false, $limit = 100)
|
||||||
|
@ -55,7 +78,7 @@ class PublicTimelineService {
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
->latest()
|
->orderByDesc('id')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->pluck('id');
|
->pluck('id');
|
||||||
foreach($ids as $id) {
|
foreach($ids as $id) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ class StatusService {
|
||||||
|
|
||||||
public static function del($id)
|
public static function del($id)
|
||||||
{
|
{
|
||||||
|
PublicTimelineService::rem($id);
|
||||||
return Cache::forget(self::key($id));
|
return Cache::forget(self::key($id));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue