فهرست منبع

Merge pull request #3897 from pixelfed/staging

Add db migration, add profile indexes
daniel 2 سال پیش
والد
کامیت
6a3286c057

+ 16 - 5
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;

+ 17 - 5
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;

+ 17 - 5
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;

+ 34 - 0
database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('profiles', function (Blueprint $table) {
+            $table->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');
+        });
+    }
+};