Update HashtagService

This commit is contained in:
Daniel Supernault 2023-05-09 03:22:28 -06:00
parent b5fe956acf
commit 0b42fe0f00
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
2 changed files with 15 additions and 7 deletions

View File

@ -3249,7 +3249,8 @@ class ApiV1Controller extends Controller
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|max:100',
'only_media' => 'sometimes|boolean'
'only_media' => 'sometimes|boolean',
'_pe' => 'sometimes'
]);
if(config('database.default') === 'pgsql') {
@ -3274,6 +3275,7 @@ class ApiV1Controller extends Controller
$max = $request->input('max_id');
$limit = $request->input('limit', 20);
$onlyMedia = $request->input('only_media', true);
$pe = $request->has(self::PF_API_ENTITY_KEY);
if($min || $max) {
$minMax = SnowflakeService::byDate(now()->subMonths(6));
@ -3294,13 +3296,13 @@ class ApiV1Controller extends Controller
}
$res = StatusHashtag::whereHashtagId($tag->id)
->where('status_id', $dir, $id)
->whereStatusVisibility('public')
->where('status_id', $dir, $id)
->orderBy('status_id', 'desc')
->limit($limit)
->pluck('status_id')
->map(function ($i) {
return StatusService::getMastodon($i);
->map(function ($i) use($pe) {
return $pe ? StatusService::get($i) : StatusService::getMastodon($i);
})
->filter(function($i) use($onlyMedia) {
if(!$i) {
@ -3977,11 +3979,17 @@ class ApiV1Controller extends Controller
];
}
return [
$res = [
'name' => $tag->name,
'url' => config('app.url') . '/i/web/hashtag/' . $tag->slug,
'history' => [],
'following' => HashtagService::isFollowing($pid, $tag->id)
];
if($request->has(self::PF_API_ENTITY_KEY)) {
$res['count'] = HashtagService::count($tag->id);
}
return $this->json($res);
}
}

View File

@ -28,8 +28,8 @@ class HashtagService {
public static function count($id)
{
return Cache::remember('services:hashtag:count:by_id:' . $id, 3600, function() use($id) {
return StatusHashtag::whereHashtagId($id)->count();
return Cache::remember('services:hashtag:public-count:by_id:' . $id, 86400, function() use($id) {
return StatusHashtag::whereHashtagId($id)->whereStatusVisibility('public')->count();
});
}