mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-29 09:43:16 +00:00
Update StatusHashtagService
This commit is contained in:
parent
8a47b03a1b
commit
eab5fceb9f
1 changed files with 16 additions and 18 deletions
|
@ -13,24 +13,18 @@ class StatusHashtagService {
|
||||||
|
|
||||||
const CACHE_KEY = 'pf:services:status-hashtag:collection:';
|
const CACHE_KEY = 'pf:services:status-hashtag:collection:';
|
||||||
|
|
||||||
public static function get($id, $start = 0, $stop = 100)
|
public static function get($id, $page = 1, $stop = 9)
|
||||||
{
|
{
|
||||||
$res = collect([]);
|
return StatusHashtag::whereHashtagId($id)
|
||||||
$key = self::CACHE_KEY . $id;
|
->whereHas('media')
|
||||||
$stop = $stop > 2000 ? 2000 : $stop;
|
->skip($stop)
|
||||||
$ids = Redis::zrevrangebyscore($key, $start, $stop);
|
->latest()
|
||||||
if(empty($ids)) {
|
->take(9)
|
||||||
if(self::count($id) == 0) {
|
->pluck('status_id')
|
||||||
$ids = self::coldGet($id, 0, 2000);
|
->map(function ($i, $k) use ($id) {
|
||||||
$ids = $ids->splice($start, $stop);
|
return self::getStatus($i, $id);
|
||||||
} else {
|
})
|
||||||
$ids = self::coldGet($id, $start, $stop);
|
->all();
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach($ids as $statusId) {
|
|
||||||
$res->push(self::getStatus($statusId, $id));
|
|
||||||
}
|
|
||||||
return $res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function coldGet($id, $start = 0, $stop = 2000)
|
public static function coldGet($id, $start = 0, $stop = 2000)
|
||||||
|
@ -60,7 +54,11 @@ class StatusHashtagService {
|
||||||
|
|
||||||
public static function count($id)
|
public static function count($id)
|
||||||
{
|
{
|
||||||
return Redis::zcount(self::CACHE_KEY . $id, '-inf', '+inf');
|
$count = Redis::zcount(self::CACHE_KEY . $id, '-inf', '+inf');
|
||||||
|
if(empty($count)) {
|
||||||
|
$count = StatusHashtag::whereHashtagId($id)->count();
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getStatus($statusId, $hashtagId)
|
public static function getStatus($statusId, $hashtagId)
|
||||||
|
|
Loading…
Reference in a new issue