Update PublicApiController, use account service

pull/2895/head
Daniel Supernault 2021-07-26 18:47:40 -06:00
rodzic 2376580eb7
commit ee0028bc57
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 0DEF1C662C9033F7
3 zmienionych plików z 22 dodań i 30 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ use App\Services\{
AccountService,
LikeService,
PublicTimelineService,
ProfileService,
StatusService,
SnowflakeService,
UserFilterService
@ -593,6 +594,7 @@ class PublicApiController extends Controller
abort_unless(Auth::check(), 403);
$profile = Profile::with('user')->whereNull('status')->findOrFail($id);
$owner = Auth::id() == $profile->user_id;
if(Auth::id() != $profile->user_id && $profile->is_private) {
return response()->json([]);
}
@ -602,9 +604,15 @@ class PublicApiController extends Controller
if(!$owner && $request->page > 5) {
return [];
}
$followers = $profile->followers()->orderByDesc('followers.created_at')->paginate(10);
$resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
$res = Follower::select('id', 'profile_id', 'following_id')
->whereFollowingId($profile->id)
->orderByDesc('id')
->simplePaginate(10)
->map(function($follower) {
return ProfileService::get($follower['profile_id']);
})
->toArray();
return response()->json($res);
}

Wyświetl plik

@ -8,8 +8,8 @@ use App\Transformer\Api\AccountTransformer;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
class AccountService {
class AccountService
{
const CACHE_KEY = 'pf:services:account:';
public static function get($id)
@ -19,7 +19,7 @@ class AccountService {
}
$key = self::CACHE_KEY . $id;
$ttl = now()->addMinutes(15);
$ttl = now()->addHours(12);
return Cache::remember($key, $ttl, function() use($id) {
$fractal = new Fractal\Manager();
@ -35,4 +35,4 @@ class AccountService {
return Cache::forget(self::CACHE_KEY . $id);
}
}
}

Wyświetl plik

@ -2,31 +2,15 @@
namespace App\Services;
use Cache;
use Illuminate\Support\Facades\Redis;
use App\Transformer\Api\AccountTransformer;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Profile;
class ProfileService {
class ProfileService
{
public static function get($id)
{
$key = 'profile:model:' . $id;
$ttl = now()->addHours(4);
$res = Cache::remember($key, $ttl, function() use($id) {
$profile = Profile::find($id);
if(!$profile) {
return false;
}
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
return $fractal->createData($resource)->toArray();
});
return $res;
return AccountService::get($id);
}
public static function del($id)
{
return AccountService::del($id);
}
}