-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increases the performance of HTTP requests requiring sanctum authentication
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken; | ||
|
||
class PersonalAccessToken extends SanctumPersonalAccessToken | ||
{ | ||
/** | ||
* @param array $options | ||
* @return void | ||
*/ | ||
public function save(array $options = []): void | ||
{ | ||
$changes = $this->getDirty(); | ||
|
||
/** | ||
* Update the last_used_at field no more than 1 time per minute. | ||
* This change increases the performance of HTTP requests requiring sanctum authentication. | ||
*/ | ||
if ( | ||
!array_key_exists('last_used_at', $changes) || | ||
count($changes) > 1 || | ||
!$this->getOriginal('last_used_at') || | ||
$this->getOriginal('last_used_at') < now()->parse($changes['last_used_at'])->subMinute() | ||
) { | ||
parent::save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters