From 3295dfa16e15208d73f917193bb3546d64af05bf Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 4 Dec 2022 23:53:39 -0700 Subject: [PATCH 1/2] Add db migration, add profile indexes --- ...156_add_key_id_index_to_profiles_table.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php diff --git a/database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php b/database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php new file mode 100644 index 000000000..32cf0af65 --- /dev/null +++ b/database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php @@ -0,0 +1,34 @@ +index('key_id'); + $table->index('remote_url'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('profiles', function (Blueprint $table) { + $table->dropIndex('profiles_key_id_index'); + $table->dropIndex('profiles_remote_url_index'); + }); + } +}; From 1fac8d545c429e22f09c78aaf047c727c3cea413 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 5 Dec 2022 00:16:38 -0700 Subject: [PATCH 2/2] Update InboxPipeline --- app/Jobs/InboxPipeline/DeleteWorker.php | 21 ++++++++++++++++----- app/Jobs/InboxPipeline/InboxValidator.php | 22 +++++++++++++++++----- app/Jobs/InboxPipeline/InboxWorker.php | 22 +++++++++++++++++----- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/app/Jobs/InboxPipeline/DeleteWorker.php b/app/Jobs/InboxPipeline/DeleteWorker.php index dead58163..74039d40a 100644 --- a/app/Jobs/InboxPipeline/DeleteWorker.php +++ b/app/Jobs/InboxPipeline/DeleteWorker.php @@ -14,8 +14,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zttp\Zttp; use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; +use Illuminate\Support\Facades\Http; +use Illuminate\Http\Client\ConnectionException; class DeleteWorker implements ShouldQueue { @@ -200,10 +201,20 @@ class DeleteWorker implements ShouldQueue if(Helpers::validateUrl($actor->remote_url) == false) { return; } - $res = Zttp::timeout(60)->withHeaders([ - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', - ])->get($actor->remote_url); + + try { + $res = Http::timeout(20)->withHeaders([ + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', + ])->get($actor->remote_url); + } catch (ConnectionException $e) { + return false; + } + + if(!$res->ok()) { + return false; + } + $res = json_decode($res->body(), true, 8); if(!isset($res['publicKey'], $res['publicKey']['id'])) { return; diff --git a/app/Jobs/InboxPipeline/InboxValidator.php b/app/Jobs/InboxPipeline/InboxValidator.php index 366d81326..3587ec2f5 100644 --- a/app/Jobs/InboxPipeline/InboxValidator.php +++ b/app/Jobs/InboxPipeline/InboxValidator.php @@ -14,8 +14,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zttp\Zttp; use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; +use Illuminate\Support\Facades\Http; +use Illuminate\Http\Client\ConnectionException; class InboxValidator implements ShouldQueue { @@ -27,6 +28,7 @@ class InboxValidator implements ShouldQueue public $timeout = 60; public $tries = 1; + public $maxExceptions = 1; /** * Create a new job instance. @@ -177,10 +179,20 @@ class InboxValidator implements ShouldQueue if(Helpers::validateUrl($actor->remote_url) == false) { return; } - $res = Zttp::timeout(60)->withHeaders([ - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', - ])->get($actor->remote_url); + + try { + $res = Http::timeout(20)->withHeaders([ + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', + ])->get($actor->remote_url); + } catch (ConnectionException $e) { + return false; + } + + if(!$res->ok()) { + return false; + } + $res = json_decode($res->body(), true, 8); if(!$res || empty($res) || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { return; diff --git a/app/Jobs/InboxPipeline/InboxWorker.php b/app/Jobs/InboxPipeline/InboxWorker.php index e3165666a..be5eaab95 100644 --- a/app/Jobs/InboxPipeline/InboxWorker.php +++ b/app/Jobs/InboxPipeline/InboxWorker.php @@ -14,8 +14,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zttp\Zttp; use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; +use Illuminate\Support\Facades\Http; +use Illuminate\Http\Client\ConnectionException; class InboxWorker implements ShouldQueue { @@ -26,6 +27,7 @@ class InboxWorker implements ShouldQueue public $timeout = 60; public $tries = 1; + public $maxExceptions = 1; /** * Create a new job instance. @@ -163,10 +165,20 @@ class InboxWorker implements ShouldQueue if(Helpers::validateUrl($actor->remote_url) == false) { return; } - $res = Zttp::timeout(60)->withHeaders([ - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', - ])->get($actor->remote_url); + + try { + $res = Http::timeout(20)->withHeaders([ + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', + ])->get($actor->remote_url); + } catch (ConnectionException $e) { + return false; + } + + if(!$res->ok()) { + return false; + } + $res = json_decode($res->body(), true, 8); if(!$res || empty($res) || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { return;