2019-07-01 04:27:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2019-12-11 06:04:03 +00:00
|
|
|
use Cache;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
2019-07-01 04:27:27 +00:00
|
|
|
use App\{Status, StatusHashtag};
|
|
|
|
use App\Transformer\Api\StatusHashtagTransformer;
|
|
|
|
use League\Fractal;
|
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
|
|
|
|
class StatusHashtagService {
|
|
|
|
|
|
|
|
const CACHE_KEY = 'pf:services:status-hashtag:collection:';
|
|
|
|
|
2019-07-05 02:05:28 +00:00
|
|
|
public static function get($id, $page = 1, $stop = 9)
|
2019-07-01 04:27:27 +00:00
|
|
|
{
|
2021-01-30 23:07:12 +00:00
|
|
|
if($page > 20) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2019-07-05 02:05:28 +00:00
|
|
|
return StatusHashtag::whereHashtagId($id)
|
2019-07-09 04:40:54 +00:00
|
|
|
->whereStatusVisibility('public')
|
2019-07-05 02:05:28 +00:00
|
|
|
->whereHas('media')
|
|
|
|
->skip($stop)
|
|
|
|
->latest()
|
|
|
|
->take(9)
|
|
|
|
->pluck('status_id')
|
|
|
|
->map(function ($i, $k) use ($id) {
|
|
|
|
return self::getStatus($i, $id);
|
|
|
|
})
|
|
|
|
->all();
|
2019-07-01 04:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function coldGet($id, $start = 0, $stop = 2000)
|
|
|
|
{
|
|
|
|
$stop = $stop > 2000 ? 2000 : $stop;
|
|
|
|
$ids = StatusHashtag::whereHashtagId($id)
|
2019-07-09 04:40:54 +00:00
|
|
|
->whereStatusVisibility('public')
|
2019-07-02 05:13:43 +00:00
|
|
|
->whereHas('media')
|
2019-07-01 04:27:27 +00:00
|
|
|
->latest()
|
|
|
|
->skip($start)
|
|
|
|
->take($stop)
|
|
|
|
->pluck('status_id');
|
|
|
|
foreach($ids as $key) {
|
|
|
|
self::set($id, $key);
|
|
|
|
}
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function set($key, $val)
|
|
|
|
{
|
2021-01-30 23:09:17 +00:00
|
|
|
return 1;
|
2019-07-01 04:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function del($key)
|
|
|
|
{
|
2021-01-30 23:09:17 +00:00
|
|
|
return 1;
|
2019-07-01 04:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function count($id)
|
|
|
|
{
|
2019-09-11 04:03:45 +00:00
|
|
|
$key = 'pf:services:status-hashtag:count:' . $id;
|
2019-10-17 06:19:02 +00:00
|
|
|
$ttl = now()->addMinutes(5);
|
2019-09-11 04:03:45 +00:00
|
|
|
return Cache::remember($key, $ttl, function() use($id) {
|
2021-01-31 06:13:54 +00:00
|
|
|
return StatusHashtag::whereHashtagId($id)->has('media')->count();
|
2019-09-11 04:03:45 +00:00
|
|
|
});
|
2019-07-01 04:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getStatus($statusId, $hashtagId)
|
|
|
|
{
|
2021-01-30 23:07:12 +00:00
|
|
|
return ['status' => StatusService::get($statusId)];
|
2019-07-01 04:27:27 +00:00
|
|
|
}
|
|
|
|
}
|