From 702c5fb4f26a1d0ae5e156c299dbd9e69df30adf Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 1 Nov 2022 16:39:58 +1100 Subject: [PATCH] Indexes for performance improvements, improved FTN regex --- app/Http/Controllers/SystemController.php | 2 +- app/Models/Address.php | 7 ++- .../2022_10_23_092332_seenby_index.php | 47 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2022_10_23_092332_seenby_index.php diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 548ac8c..d565944 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -271,7 +271,7 @@ class SystemController extends Controller return redirect()->action([self::class,'home']); } - $o->load(['addresses.zone.domain']); + $o->load(['addresses.zone.domain','addresses.system','sessions.domain','sessions.systems']); return view('system.addedit') ->with('action',$o->exists ? 'update' : 'create') diff --git a/app/Models/Address.php b/app/Models/Address.php index 1a356e0..960d083 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -32,6 +32,9 @@ class Address extends Model protected $with = ['zone']; + // http://ftsc.org/docs/frl-1028.002 + public const ftn_regex = '([0-9]+):([0-9]+)/([0-9]+)(\.([0-9]+))?(@([a-z0-9\-_~]{0,8}))?'; + public const NODE_ZC = 1<<0; // Zone public const NODE_RC = 1<<1; // Region public const NODE_NC = 1<<2; // Host @@ -513,6 +516,7 @@ class Address extends Model } /** + * * Parse a string and split it out as an FTN array * * @param string $ftn @@ -521,8 +525,7 @@ class Address extends Model */ public static function parseFTN(string $ftn): array { - // http://ftsc.org/docs/frl-1028.002 - if (! preg_match('#^([0-9]+):([0-9]+)/([0-9]+)(.([0-9]+))?(@([a-z0-9\-_~]{0,8}))?$#',strtolower($ftn),$matches)) + if (! preg_match(sprintf('#^%s$#',self::ftn_regex),strtolower($ftn),$matches)) throw new Exception('Invalid FTN: '.$ftn); // Check our numbers are correct. diff --git a/database/migrations/2022_10_23_092332_seenby_index.php b/database/migrations/2022_10_23_092332_seenby_index.php new file mode 100644 index 0000000..ae441d9 --- /dev/null +++ b/database/migrations/2022_10_23_092332_seenby_index.php @@ -0,0 +1,47 @@ +index(['echomail_id','address_id']); + $table->index(['packet']); + $table->index(['sent_at']); + $table->index(['export_at']); + }); + + Schema::table('echomails', function (Blueprint $table) { + $table->index(['msgid']); + $table->index(['replyid']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('echomails', function (Blueprint $table) { + $table->dropIndex(['msgid']); + $table->dropIndex(['replyid']); + }); + Schema::table('echomail_seenby', function (Blueprint $table) { + $table->dropIndex(['packet']); + $table->dropIndex(['sent_at']); + $table->dropIndex(['export_at']); + $table->dropIndex(['echomail_id','address_id']); + }); + } +};