mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-29 09:43:16 +00:00
Update HashtagService
This commit is contained in:
parent
b5fe956acf
commit
0b42fe0f00
2 changed files with 15 additions and 7 deletions
|
@ -3249,7 +3249,8 @@ class ApiV1Controller extends Controller
|
||||||
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'limit' => 'nullable|integer|max:100',
|
'limit' => 'nullable|integer|max:100',
|
||||||
'only_media' => 'sometimes|boolean'
|
'only_media' => 'sometimes|boolean',
|
||||||
|
'_pe' => 'sometimes'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if(config('database.default') === 'pgsql') {
|
if(config('database.default') === 'pgsql') {
|
||||||
|
@ -3274,6 +3275,7 @@ class ApiV1Controller extends Controller
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit', 20);
|
$limit = $request->input('limit', 20);
|
||||||
$onlyMedia = $request->input('only_media', true);
|
$onlyMedia = $request->input('only_media', true);
|
||||||
|
$pe = $request->has(self::PF_API_ENTITY_KEY);
|
||||||
|
|
||||||
if($min || $max) {
|
if($min || $max) {
|
||||||
$minMax = SnowflakeService::byDate(now()->subMonths(6));
|
$minMax = SnowflakeService::byDate(now()->subMonths(6));
|
||||||
|
@ -3294,13 +3296,13 @@ class ApiV1Controller extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = StatusHashtag::whereHashtagId($tag->id)
|
$res = StatusHashtag::whereHashtagId($tag->id)
|
||||||
->where('status_id', $dir, $id)
|
|
||||||
->whereStatusVisibility('public')
|
->whereStatusVisibility('public')
|
||||||
|
->where('status_id', $dir, $id)
|
||||||
->orderBy('status_id', 'desc')
|
->orderBy('status_id', 'desc')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->pluck('status_id')
|
->pluck('status_id')
|
||||||
->map(function ($i) {
|
->map(function ($i) use($pe) {
|
||||||
return StatusService::getMastodon($i);
|
return $pe ? StatusService::get($i) : StatusService::getMastodon($i);
|
||||||
})
|
})
|
||||||
->filter(function($i) use($onlyMedia) {
|
->filter(function($i) use($onlyMedia) {
|
||||||
if(!$i) {
|
if(!$i) {
|
||||||
|
@ -3977,11 +3979,17 @@ class ApiV1Controller extends Controller
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
$res = [
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'url' => config('app.url') . '/i/web/hashtag/' . $tag->slug,
|
'url' => config('app.url') . '/i/web/hashtag/' . $tag->slug,
|
||||||
'history' => [],
|
'history' => [],
|
||||||
'following' => HashtagService::isFollowing($pid, $tag->id)
|
'following' => HashtagService::isFollowing($pid, $tag->id)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if($request->has(self::PF_API_ENTITY_KEY)) {
|
||||||
|
$res['count'] = HashtagService::count($tag->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json($res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ class HashtagService {
|
||||||
|
|
||||||
public static function count($id)
|
public static function count($id)
|
||||||
{
|
{
|
||||||
return Cache::remember('services:hashtag:count:by_id:' . $id, 3600, function() use($id) {
|
return Cache::remember('services:hashtag:public-count:by_id:' . $id, 86400, function() use($id) {
|
||||||
return StatusHashtag::whereHashtagId($id)->count();
|
return StatusHashtag::whereHashtagId($id)->whereStatusVisibility('public')->count();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue