mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-12 17:44:31 +00:00
Update ProfileService, use account transformer
This commit is contained in:
parent
9cf962fff5
commit
391b1287ac
2 changed files with 23 additions and 35 deletions
|
@ -57,7 +57,7 @@ class MediaTagService
|
||||||
|
|
||||||
protected function idToUsername($id)
|
protected function idToUsername($id)
|
||||||
{
|
{
|
||||||
$profile = ProfileService::build()->profileId($id);
|
$profile = ProfileService::get($id);
|
||||||
|
|
||||||
if(!$profile) {
|
if(!$profile) {
|
||||||
return 'unavailable';
|
return 'unavailable';
|
||||||
|
@ -65,8 +65,8 @@ class MediaTagService
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (string) $id,
|
'id' => (string) $id,
|
||||||
'username' => $profile->username,
|
'username' => $profile['username'],
|
||||||
'avatar' => $profile->avatarUrl()
|
'avatar' => $profile['avatar']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,41 +4,29 @@ namespace App\Services;
|
||||||
|
|
||||||
use Cache;
|
use Cache;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
use App\Transformer\Api\AccountTransformer;
|
||||||
use App\{
|
use League\Fractal;
|
||||||
Follower,
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
Profile
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
};
|
use App\Profile;
|
||||||
|
|
||||||
class ProfileService {
|
class ProfileService {
|
||||||
|
|
||||||
protected $profile;
|
public static function get($id)
|
||||||
protected $profile_prefix;
|
|
||||||
|
|
||||||
public static function build()
|
|
||||||
{
|
{
|
||||||
return new self();
|
$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();
|
||||||
public function profile(Profile $profile)
|
$fractal->setSerializer(new ArraySerializer());
|
||||||
{
|
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
||||||
$this->profile = $profile;
|
return $fractal->createData($resource)->toArray();
|
||||||
$this->profile_prefix = 'profile:model:'.$profile->id;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function profileId($id)
|
|
||||||
{
|
|
||||||
return Cache::rememberForever('profile:model:'.$id, function() use($id) {
|
|
||||||
return Profile::findOrFail($id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get()
|
|
||||||
{
|
|
||||||
return Cache::rememberForever($this->profile_prefix, function() {
|
|
||||||
return $this->profile;
|
|
||||||
});
|
});
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue