1
0
Fork 0
forked from mirror/pixelfed

Update AP helpers, remove cache lock from profileUpdateOrCreate method

This commit is contained in:
Daniel Supernault 2022-08-31 22:02:41 -06:00
parent 2c20d9e398
commit bc2bbc14ac
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -720,16 +720,8 @@ class Helpers {
public static function profileUpdateOrCreate($url)
{
$hash = base64_encode($url);
$key = 'ap:profile:by_url:' . $hash;
$lock = Cache::lock($key, 30);
$profile = null;
try {
$lock->block(5);
$res = self::fetchProfileFromUrl($url);
if(isset($res['id']) == false) {
if(!$res || isset($res['id']) == false) {
return;
}
$domain = parse_url($res['id'], PHP_URL_HOST);
@ -743,8 +735,12 @@ class Helpers {
$remoteUsername = $username;
$webfinger = "@{$username}@{$domain}";
abort_if(!self::validateUrl($res['inbox']), 400);
abort_if(!self::validateUrl($res['id']), 400);
if(!self::validateUrl($res['inbox'])) {
return;
}
if(!self::validateUrl($res['id'])) {
return;
}
$profile = DB::transaction(function() use($domain, $webfinger, $res) {
$instance = Instance::updateOrCreate([
@ -759,6 +755,8 @@ class Helpers {
'domain' => strtolower($domain),
'username' => Purify::clean($webfinger),
'remote_url' => $res['id'],
'webfinger' => Purify::clean($webfinger),
'key_id' => $res['publicKey']['id'],
],
[
'name' => isset($res['name']) ? Purify::clean($res['name']) : 'user',
@ -767,8 +765,6 @@ class Helpers {
'inbox_url' => $res['inbox'],
'outbox_url' => isset($res['outbox']) ? $res['outbox'] : null,
'public_key' => $res['publicKey']['publicKeyPem'],
'key_id' => $res['publicKey']['id'],
'webfinger' => Purify::clean($webfinger),
]
);
@ -783,12 +779,7 @@ class Helpers {
});
return $profile;
} catch (LockTimeoutException $e) {
} finally {
optional($lock)->release();
}
return $profile;
}
public static function profileFetch($url)