From 7793b746df594b1e6b9f742190da4da92c3bf2ca Mon Sep 17 00:00:00 2001 From: recursivetree <60423027+recursivetree@users.noreply.github.com> Date: Sat, 7 Sep 2024 01:19:02 +0200 Subject: [PATCH] fix: allow updating scheduling rules for new tokens (#687) --- .../Configuration/ScheduleController.php | 14 ++++++++++---- src/Models/CharacterSchedulingRule.php | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Http/Controllers/Configuration/ScheduleController.php b/src/Http/Controllers/Configuration/ScheduleController.php index 64a9eb6b1..6aef76ebe 100644 --- a/src/Http/Controllers/Configuration/ScheduleController.php +++ b/src/Http/Controllers/Configuration/ScheduleController.php @@ -118,8 +118,11 @@ public function createSchedulingRule(Request $request) $rule->filter = $request->filters; $rule->save(); - RefreshToken::all()->each(function ($token) { - CharacterSchedulingRule::updateRefreshTokenSchedule($token); + // chunk this to avoid out-of-memory issues on large installs + RefreshToken::chunk(200, function ($tokens) { + foreach ($tokens as $token) { + CharacterSchedulingRule::updateRefreshTokenSchedule($token); + } }); return redirect()->back() @@ -134,8 +137,11 @@ public function deleteSchedulingRule(Request $request) CharacterSchedulingRule::destroy($request->rule_id); - RefreshToken::all()->each(function ($token) { - CharacterSchedulingRule::updateRefreshTokenSchedule($token); + // chunk this to avoid out-of-memory issues on large installs + RefreshToken::chunk(200, function ($tokens) { + foreach ($tokens as $token) { + CharacterSchedulingRule::updateRefreshTokenSchedule($token); + } }); return redirect()->back()->with('success', 'Successfully removed character scheduling rule!'); diff --git a/src/Models/CharacterSchedulingRule.php b/src/Models/CharacterSchedulingRule.php index 471a5f6f7..e903f5bd4 100644 --- a/src/Models/CharacterSchedulingRule.php +++ b/src/Models/CharacterSchedulingRule.php @@ -66,6 +66,7 @@ public static function updateRefreshTokenSchedule(RefreshToken $token): void if($schedule === null) { $schedule = new RefreshTokenSchedule(); $schedule->character_id = $token->character_id; + $schedule->last_update = now()->subYears(10); // Hopefully this is far enough in the past to mean never? } $schedule->update_interval = self::getCharacterSchedulingInterval($token->character);