From 176194cba257dd6cd75d9086c17d4e4b42d0ca92 Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:42:48 +0200 Subject: [PATCH 1/7] remove character filter observers --- .../CharacterAffiliationObserver.php | 64 -------------- src/Observers/CharacterAssetObserver.php | 71 ---------------- src/Observers/CharacterRoleObserver.php | 31 +------ src/Observers/CharacterSkillObserver.php | 84 ------------------- src/Observers/CharacterTitleObserver.php | 71 ---------------- src/Observers/RefreshTokenObserver.php | 51 +---------- src/WebServiceProvider.php | 4 - 7 files changed, 2 insertions(+), 374 deletions(-) delete mode 100644 src/Observers/CharacterAffiliationObserver.php delete mode 100644 src/Observers/CharacterAssetObserver.php delete mode 100644 src/Observers/CharacterSkillObserver.php delete mode 100644 src/Observers/CharacterTitleObserver.php diff --git a/src/Observers/CharacterAffiliationObserver.php b/src/Observers/CharacterAffiliationObserver.php deleted file mode 100644 index 116179fa5..000000000 --- a/src/Observers/CharacterAffiliationObserver.php +++ /dev/null @@ -1,64 +0,0 @@ -fireCharacterFilterEvent($affiliation); - } - - /** - * @param \Seat\Eveapi\Models\Character\CharacterAffiliation $affiliation - */ - public function updated(CharacterAffiliation $affiliation) - { - $this->fireCharacterFilterEvent($affiliation); - } - - /** - * Return the User owning the model which fired the catch event. - * - * @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event - * @return ?CharacterInfo The character that is affected by this update - */ - protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo - { - // CharacterAffiliation links to UniverseName instead of CharacterInfo - return CharacterInfo::find($fired_model->character_id); - } -} diff --git a/src/Observers/CharacterAssetObserver.php b/src/Observers/CharacterAssetObserver.php deleted file mode 100644 index 67f2b9f15..000000000 --- a/src/Observers/CharacterAssetObserver.php +++ /dev/null @@ -1,71 +0,0 @@ -fireCharacterFilterEvent($asset); - } - - /** - * @param \Seat\Eveapi\Models\Assets\CharacterAsset $asset - */ - public function updated(CharacterAsset $asset) - { - $this->fireCharacterFilterEvent($asset); - } - - /** - * @param \Seat\Eveapi\Models\Assets\CharacterAsset $asset - */ - public function deleted(CharacterAsset $asset) - { - $this->fireCharacterFilterEvent($asset); - } - - /** - * Return the User owning the model which fired the catch event. - * - * @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event - * @return ?CharacterInfo The character that is affected by this update - */ - protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo - { - return $fired_model->character; - } -} diff --git a/src/Observers/CharacterRoleObserver.php b/src/Observers/CharacterRoleObserver.php index 688f6f9b1..21d853ef1 100644 --- a/src/Observers/CharacterRoleObserver.php +++ b/src/Observers/CharacterRoleObserver.php @@ -35,15 +35,13 @@ * * @package Seat\Web\Observers */ -class CharacterRoleObserver extends AbstractCharacterFilterObserver +class CharacterRoleObserver { /** * @param \Seat\Eveapi\Models\Character\CharacterRole $role */ public function created(CharacterRole $role) { - $this->fireCharacterFilterEvent($role); - // in case the created role is not a Director role, ignore if ($role->role != 'Director') return; @@ -62,31 +60,4 @@ public function created(CharacterRole $role) logger()->error($e->getMessage()); } } - - /** - * @param \Seat\Eveapi\Models\Character\CharacterRole $role - */ - public function updated(CharacterRole $role) - { - $this->fireCharacterFilterEvent($role); - } - - /** - * @param \Seat\Eveapi\Models\Character\CharacterRole $role - */ - public function deleted(CharacterRole $role) - { - $this->fireCharacterFilterEvent($role); - } - - /** - * Return the User owning the model which fired the catch event. - * - * @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event - * @return ?CharacterInfo The character that is affected by this update - */ - protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo - { - return $fired_model->character; - } } diff --git a/src/Observers/CharacterSkillObserver.php b/src/Observers/CharacterSkillObserver.php deleted file mode 100644 index f3c7e1820..000000000 --- a/src/Observers/CharacterSkillObserver.php +++ /dev/null @@ -1,84 +0,0 @@ -fireCharacterFilterEvent($skill); - } - - /** - * @param \Seat\Eveapi\Models\Character\CharacterSkill $skill - */ - public function updated(CharacterSkill $skill) - { - $this->fireCharacterFilterEvent($skill); - } - - /** - * @param \Seat\Eveapi\Models\Character\CharacterSkill $skill - */ - public function deleted(CharacterSkill $skill) - { - $this->fireCharacterFilterEvent($skill); - } - - /** - * {@inheritdoc} - */ - protected function findRelatedUser(Model $fired_model): ?User - { - // retrieve user related to the character affiliation - return User::with('squads') - ->standard() - ->whereHas('characters', function ($query) use ($fired_model) { - $query->where('character_infos.character_id', $fired_model->character_id); - })->first(); - } - - /** - * Return the User owning the model which fired the catch event. - * - * @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event - * @return ?CharacterInfo The character that is affected by this update - */ - protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo - { - return $fired_model->character; - } -} diff --git a/src/Observers/CharacterTitleObserver.php b/src/Observers/CharacterTitleObserver.php deleted file mode 100644 index d01b033fd..000000000 --- a/src/Observers/CharacterTitleObserver.php +++ /dev/null @@ -1,71 +0,0 @@ -fireCharacterFilterEvent($title); - } - - /** - * @param \Seat\Eveapi\Models\Assets\CharacterAsset $asset - */ - public function updated(CharacterTitle $title) - { - $this->fireCharacterFilterEvent($title); - } - - /** - * @param \Seat\Eveapi\Models\Assets\CharacterAsset $asset - */ - public function deleted(CharacterTitle $title) - { - $this->fireCharacterFilterEvent($title); - } - - /** - * Return the User owning the model which fired the catch event. - * - * @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event - * @return ?CharacterInfo The character that is affected by this update - */ - protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo - { - return CharacterInfo::find($fired_model->character_id); - } -} diff --git a/src/Observers/RefreshTokenObserver.php b/src/Observers/RefreshTokenObserver.php index 901e91bef..2589e3f1c 100644 --- a/src/Observers/RefreshTokenObserver.php +++ b/src/Observers/RefreshTokenObserver.php @@ -34,7 +34,7 @@ * * @package Seat\Web\Observers */ -class RefreshTokenObserver extends AbstractCharacterFilterObserver +class RefreshTokenObserver { /** * @param \Seat\Eveapi\Models\RefreshToken $token @@ -44,41 +44,6 @@ public function created(RefreshToken $token) try { $job = new Character($token->character_id, $token); $job->fire(); - - // enqueue squads update - $this->fireCharacterFilterEvent($token); - } catch (Exception $e) { - logger()->error($e->getMessage()); - } - } - - /** - * @param \Seat\Eveapi\Models\RefreshToken $token - */ - public function updated(RefreshToken $token) - { - try { - $this->fireCharacterFilterEvent($token); - } catch (Exception $e) { - logger()->error($e->getMessage()); - } - } - - /** - * @param \Seat\Eveapi\Models\RefreshToken $token - */ - public function softDeleted(RefreshToken $token) - { - $this->deleted($token); - } - - /** - * @param \Seat\Eveapi\Models\RefreshToken $token - */ - public function deleted(RefreshToken $token) - { - try { - $this->fireCharacterFilterEvent($token); } catch (Exception $e) { logger()->error($e->getMessage()); } @@ -92,22 +57,8 @@ public function restored(RefreshToken $token) try { $job = new Character($token->character_id, $token); $job->fire(); - - // enqueue squads update - $this->fireCharacterFilterEvent($token); } catch (Exception $e) { logger()->error($e->getMessage()); } } - - /** - * Return the User owning the model which fired the catch event. - * - * @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event - * @return ?CharacterInfo The character that is affected by this update - */ - protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo - { - return $fired_model->character; - } } diff --git a/src/WebServiceProvider.php b/src/WebServiceProvider.php index e503a832e..8d2ee07b8 100644 --- a/src/WebServiceProvider.php +++ b/src/WebServiceProvider.php @@ -310,10 +310,6 @@ private function add_events() RefreshToken::observe(RefreshTokenObserver::class); // Squads Events - CharacterAffiliation::observe(CharacterAffiliationObserver::class); - CharacterAsset::observe(CharacterAssetObserver::class); - CharacterSkill::observe(CharacterSkillObserver::class); - CharacterTitle::observe(CharacterTitleObserver::class); SquadMember::observe(SquadMemberObserver::class); SquadRole::observe(SquadRoleObserver::class); } From 778a364c7c38d8b40aeab1a76601671c9c970d1b Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:56:57 +0200 Subject: [PATCH 2/7] forward character batch processed event --- src/Listeners/CharacterBatchProcessed.php | 14 ++++++++++++++ src/WebServiceProvider.php | 10 ++-------- 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 src/Listeners/CharacterBatchProcessed.php diff --git a/src/Listeners/CharacterBatchProcessed.php b/src/Listeners/CharacterBatchProcessed.php new file mode 100644 index 000000000..44df74cf0 --- /dev/null +++ b/src/Listeners/CharacterBatchProcessed.php @@ -0,0 +1,14 @@ +character)); + } +} \ No newline at end of file diff --git a/src/WebServiceProvider.php b/src/WebServiceProvider.php index 8d2ee07b8..c9dd09799 100644 --- a/src/WebServiceProvider.php +++ b/src/WebServiceProvider.php @@ -32,12 +32,8 @@ use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Validator; use Laravel\Horizon\Horizon; -use Seat\Eveapi\Models\Assets\CharacterAsset; -use Seat\Eveapi\Models\Character\CharacterAffiliation; use Seat\Eveapi\Models\Character\CharacterRole; -use Seat\Eveapi\Models\Character\CharacterSkill; use Seat\Eveapi\Models\RefreshToken; -use Seat\Eveapi\Pivot\Character\CharacterTitle; use Seat\Services\AbstractSeatPlugin; use Seat\Services\Settings\Profile; use Seat\Services\Settings\Seat; @@ -62,15 +58,12 @@ use Seat\Web\Http\Middleware\Locale; use Seat\Web\Http\Middleware\RegistrationAllowed; use Seat\Web\Http\Middleware\Requirements; +use Seat\Web\Listeners\CharacterBatchProcessed; use Seat\Web\Listeners\CharacterFilterDataUpdatedSquads; use Seat\Web\Listeners\CharacterFilterDataUpdatedTokens; use Seat\Web\Models\Squads\SquadMember; use Seat\Web\Models\Squads\SquadRole; -use Seat\Web\Observers\CharacterAffiliationObserver; -use Seat\Web\Observers\CharacterAssetObserver; use Seat\Web\Observers\CharacterRoleObserver; -use Seat\Web\Observers\CharacterSkillObserver; -use Seat\Web\Observers\CharacterTitleObserver; use Seat\Web\Observers\RefreshTokenObserver; use Seat\Web\Observers\SquadMemberObserver; use Seat\Web\Observers\SquadRoleObserver; @@ -302,6 +295,7 @@ private function add_events() // Custom Events Event::listen('security.log', SecLog::class); + Event::listen(\Seat\Eveapi\Events\CharacterBatchProcessed::class, CharacterBatchProcessed::class); Event::listen(CharacterFilterDataUpdate::class, CharacterFilterDataUpdatedSquads::class); Event::listen(CharacterFilterDataUpdate::class, CharacterFilterDataUpdatedTokens::class); From 95f5de3d651d44e03a0ae5d8c2815784f102b1eb Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:12:02 +0200 Subject: [PATCH 3/7] add character filter update job --- src/Commands/Seat/Filters/Update.php | 36 ++++++++++++++++++++++++++++ src/Jobs/UpdateCharacterFilters.php | 33 +++++++++++++++++++++++++ src/WebServiceProvider.php | 6 +++-- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/Commands/Seat/Filters/Update.php create mode 100644 src/Jobs/UpdateCharacterFilters.php diff --git a/src/Commands/Seat/Filters/Update.php b/src/Commands/Seat/Filters/Update.php new file mode 100644 index 000000000..591180842 --- /dev/null +++ b/src/Commands/Seat/Filters/Update.php @@ -0,0 +1,36 @@ +onQueue('high'); + $this->line('Scheduled character filter updates for all characters!'); + } +} \ No newline at end of file diff --git a/src/Jobs/UpdateCharacterFilters.php b/src/Jobs/UpdateCharacterFilters.php new file mode 100644 index 000000000..330018c69 --- /dev/null +++ b/src/Jobs/UpdateCharacterFilters.php @@ -0,0 +1,33 @@ +commands([ - AdminLogin::class, + AdminLoginCommand::class, + FilterUpdateCommand::class ]); } From f32c5c0a23c0d8d9fb9730b111d80185ee31162b Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:15:50 +0200 Subject: [PATCH 4/7] add filter update command to schedule seeder --- src/database/seeders/ScheduleSeeder.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/database/seeders/ScheduleSeeder.php b/src/database/seeders/ScheduleSeeder.php index 8db64b1fb..46fc27b48 100644 --- a/src/database/seeders/ScheduleSeeder.php +++ b/src/database/seeders/ScheduleSeeder.php @@ -47,6 +47,14 @@ public function getSchedules(): array 'ping_before' => null, 'ping_after' => null, ], + [ + 'command' => 'seat:filters:update', + 'expression' => sprintf('%d * * * *', rand(0, 59)), + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ] ]; } From 5db867a9f90d4c4ed2183c1b93265777ba4cec1a Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:21:34 +0200 Subject: [PATCH 5/7] styleci --- src/Commands/Seat/Filters/Update.php | 25 ++++++++++++++++++++-- src/Jobs/UpdateCharacterFilters.php | 26 ++++++++++++++++++++--- src/Listeners/CharacterBatchProcessed.php | 24 +++++++++++++++++++-- src/Observers/CharacterRoleObserver.php | 3 --- src/Observers/RefreshTokenObserver.php | 3 --- src/WebServiceProvider.php | 2 +- src/database/seeders/ScheduleSeeder.php | 2 +- 7 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/Commands/Seat/Filters/Update.php b/src/Commands/Seat/Filters/Update.php index 591180842..e371efda0 100644 --- a/src/Commands/Seat/Filters/Update.php +++ b/src/Commands/Seat/Filters/Update.php @@ -1,5 +1,25 @@ onQueue('high'); $this->line('Scheduled character filter updates for all characters!'); } -} \ No newline at end of file +} diff --git a/src/Jobs/UpdateCharacterFilters.php b/src/Jobs/UpdateCharacterFilters.php index 330018c69..d3dc9cce5 100644 --- a/src/Jobs/UpdateCharacterFilters.php +++ b/src/Jobs/UpdateCharacterFilters.php @@ -1,5 +1,25 @@ character)); } -} \ No newline at end of file +} diff --git a/src/Observers/CharacterRoleObserver.php b/src/Observers/CharacterRoleObserver.php index 21d853ef1..41fb4c431 100644 --- a/src/Observers/CharacterRoleObserver.php +++ b/src/Observers/CharacterRoleObserver.php @@ -23,12 +23,9 @@ namespace Seat\Web\Observers; use Exception; -use Illuminate\Database\Eloquent\Model; use Seat\Eveapi\Bus\Corporation; -use Seat\Eveapi\Models\Character\CharacterInfo; use Seat\Eveapi\Models\Character\CharacterRole; use Seat\Eveapi\Models\RefreshToken; -use Seat\Web\Models\User; /** * Class CharacterRoleObserver. diff --git a/src/Observers/RefreshTokenObserver.php b/src/Observers/RefreshTokenObserver.php index 2589e3f1c..1cd581baa 100644 --- a/src/Observers/RefreshTokenObserver.php +++ b/src/Observers/RefreshTokenObserver.php @@ -23,11 +23,8 @@ namespace Seat\Web\Observers; use Exception; -use Illuminate\Database\Eloquent\Model; use Seat\Eveapi\Bus\Character; -use Seat\Eveapi\Models\Character\CharacterInfo; use Seat\Eveapi\Models\RefreshToken; -use Seat\Web\Models\User; /** * Class RefreshTokenObserver. diff --git a/src/WebServiceProvider.php b/src/WebServiceProvider.php index 5685fed86..ba3b9aee1 100644 --- a/src/WebServiceProvider.php +++ b/src/WebServiceProvider.php @@ -414,7 +414,7 @@ private function addCommands() { $this->commands([ AdminLoginCommand::class, - FilterUpdateCommand::class + FilterUpdateCommand::class, ]); } diff --git a/src/database/seeders/ScheduleSeeder.php b/src/database/seeders/ScheduleSeeder.php index 46fc27b48..cc9f2d842 100644 --- a/src/database/seeders/ScheduleSeeder.php +++ b/src/database/seeders/ScheduleSeeder.php @@ -54,7 +54,7 @@ public function getSchedules(): array 'allow_maintenance' => false, 'ping_before' => null, 'ping_after' => null, - ] + ], ]; } From 2985b60bb0fb0274d7e13d04bbdaf3ad156112a8 Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:21:18 +0200 Subject: [PATCH 6/7] chunk character filter updates --- src/Jobs/UpdateCharacterFilters.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Jobs/UpdateCharacterFilters.php b/src/Jobs/UpdateCharacterFilters.php index d3dc9cce5..df4870e7a 100644 --- a/src/Jobs/UpdateCharacterFilters.php +++ b/src/Jobs/UpdateCharacterFilters.php @@ -45,9 +45,11 @@ public function tags() */ public function handle() { - $characters = CharacterInfo::all(); - foreach ($characters as $character){ - event(new CharacterFilterDataUpdate($character)); - } + // without chunking, we can run out of memory on large installs + CharacterInfo::chunk(200, function ($characters){ + foreach ($characters as $character){ + event(new CharacterFilterDataUpdate($character)); + } + }); } } From 68a451eaa8d5b3108a5f19cf86a9571db847aa52 Mon Sep 17 00:00:00 2001 From: Crypta Eve Date: Fri, 6 Sep 2024 23:13:47 +0930 Subject: [PATCH 7/7] styleci --- src/Jobs/UpdateCharacterFilters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jobs/UpdateCharacterFilters.php b/src/Jobs/UpdateCharacterFilters.php index df4870e7a..d9ad3347f 100644 --- a/src/Jobs/UpdateCharacterFilters.php +++ b/src/Jobs/UpdateCharacterFilters.php @@ -46,7 +46,7 @@ public function tags() public function handle() { // without chunking, we can run out of memory on large installs - CharacterInfo::chunk(200, function ($characters){ + CharacterInfo::chunk(200, function ($characters) { foreach ($characters as $character){ event(new CharacterFilterDataUpdate($character)); }