mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-09-20 00:08:01 +00:00
Update federation pipeline, add locks
This commit is contained in:
parent
c55f14764f
commit
ddc768871b
3 changed files with 75 additions and 40 deletions
|
@ -53,6 +53,15 @@ class InboxValidator implements ShouldQueue
|
|||
|
||||
$profile = Profile::whereNull('domain')->whereUsername($username)->first();
|
||||
|
||||
if(isset($payload['id'])) {
|
||||
$lockKey = hash('sha256', $payload['id']);
|
||||
if(Cache::get($lockKey) !== null) {
|
||||
// Job processed already
|
||||
return 1;
|
||||
}
|
||||
Cache::put($lockKey, 1, 300);
|
||||
}
|
||||
|
||||
if(!isset($headers['signature']) || !isset($headers['date'])) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,15 @@ class InboxWorker implements ShouldQueue
|
|||
$headers = $this->headers;
|
||||
$payload = json_decode($this->payload, true, 8);
|
||||
|
||||
if(isset($payload['id'])) {
|
||||
$lockKey = hash('sha256', $payload['id']);
|
||||
if(Cache::get($lockKey) !== null) {
|
||||
// Job processed already
|
||||
return 1;
|
||||
}
|
||||
Cache::put($lockKey, 1, 300);
|
||||
}
|
||||
|
||||
if(!isset($headers['signature']) || !isset($headers['date'])) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -346,7 +346,20 @@ class Helpers {
|
|||
$reply_to = null;
|
||||
}
|
||||
$ts = is_array($res['published']) ? $res['published'][0] : $res['published'];
|
||||
$status = DB::transaction(function() use($profile, $res, $url, $ts, $reply_to, $cw, $scope, $id) {
|
||||
|
||||
$statusLockKey = 'helpers:status-lock:' . hash('sha256', $res['id']);
|
||||
$status = Cache::lock($statusLockKey)
|
||||
->get(function () use(
|
||||
$profile,
|
||||
$res,
|
||||
$url,
|
||||
$ts,
|
||||
$reply_to,
|
||||
$cw,
|
||||
$scope,
|
||||
$id
|
||||
) {
|
||||
return DB::transaction(function() use($profile, $res, $url, $ts, $reply_to, $cw, $scope, $id) {
|
||||
$status = new Status;
|
||||
$status->profile_id = $profile->id;
|
||||
$status->url = isset($res['url']) ? $res['url'] : $url;
|
||||
|
@ -368,6 +381,7 @@ class Helpers {
|
|||
}
|
||||
return $status;
|
||||
});
|
||||
});
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
@ -458,7 +472,9 @@ class Helpers {
|
|||
|
||||
$profile = Profile::whereRemoteUrl($res['id'])->first();
|
||||
if(!$profile) {
|
||||
$profile = DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
|
||||
$profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']);
|
||||
$profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) {
|
||||
return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
|
||||
$profile = new Profile();
|
||||
$profile->domain = strtolower($domain);
|
||||
$profile->username = strtolower(Purify::clean($webfinger));
|
||||
|
@ -478,6 +494,7 @@ class Helpers {
|
|||
}
|
||||
return $profile;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Update info after 24 hours
|
||||
if($profile->last_fetched_at == null ||
|
||||
|
|
Loading…
Reference in a new issue