Update StatusHashtagService

This commit is contained in:
Daniel Supernault 2019-07-04 20:05:28 -06:00
parent 8a47b03a1b
commit eab5fceb9f
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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)