1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2025-02-21 13:46:55 +00:00

Update Helpers, cache profiles

This commit is contained in:
Daniel Supernault 2021-01-07 00:25:45 -07:00
parent 058637279e
commit 1f672ecfb8
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -403,9 +403,13 @@ class Helpers {
public static function profileFirstOrNew($url, $runJobs = false)
{
$url = self::validateUrl($url);
if($url == false) {
abort(400, 'Invalid url');
if($url == false || strlen($url) > 190) {
return;
}
$hash = base64_encode($url);
$key = 'ap:profile:by_url:' . $hash;
$ttl = now()->addMinutes(5);
$profile = Cache::remember($key, $ttl, function() use($url, $runJobs) {
$host = parse_url($url, PHP_URL_HOST);
$local = config('pixelfed.domain.app') == $host ? true : false;
@ -436,6 +440,7 @@ class Helpers {
$profile = Profile::whereRemoteUrl($res['id'])->first();
if(!$profile) {
$profile = DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
$profile = new Profile();
$profile->domain = strtolower($domain);
$profile->username = strtolower(Purify::clean($webfinger));
@ -454,6 +459,8 @@ class Helpers {
// RemoteFollowImportRecent::dispatch($res, $profile);
CreateAvatar::dispatch($profile);
}
return $profile;
});
} else {
// Update info after 24 hours
if($profile->last_fetched_at == null ||
@ -467,6 +474,8 @@ class Helpers {
}
}
return $profile;
});
return $profile;
}
public static function profileFetch($url)