Skip to content

Commit

Permalink
fix: allow updating scheduling rules for new tokens (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
recursivetree authored Sep 6, 2024
1 parent 6c7dd18 commit 7793b74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Http/Controllers/Configuration/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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!');
Expand Down
1 change: 1 addition & 0 deletions src/Models/CharacterSchedulingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7793b74

Please sign in to comment.