Skip to content

Commit

Permalink
Only write the user.json on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Feb 19, 2025
1 parent e00967b commit 8c93b48
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/Config/UserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,26 +397,33 @@ protected function initialize(): void
{
parent::initialize();

$hasChanges = false;

if ([] !== $this->data && (!isset($this->data['version']) || (int) $this->data['version'] < 2)) {
throw new \RuntimeException('Unsupported user.json version');
}

if (!isset($this->data['version'])) {
$this->data['version'] = 2;
$hasChanges = true;
}

foreach (($this->data['tokens'] ?? []) as $id => $token) {
if (isset($token['expires']) && $token['expires'] < time()) {
unset($this->data['tokens'][$id]);
$hasChanges = true;
}
}

foreach (($this->data['webauthn'] ?? []) as $key => $data) {
if (($data['expires'] ?? 0) < time()) {
unset($this->data['webauthn'][$key]);
$hasChanges = true;
}
}

$this->save();
if ($hasChanges) {
$this->save();
}
}
}

0 comments on commit 8c93b48

Please sign in to comment.