Update AccountService, add setLastActive method

This commit is contained in:
Daniel Supernault 2023-12-13 06:30:05 -07:00
parent 85839b220a
commit ebbd98e743
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -166,7 +166,7 @@ class AccountService
public static function usernameToId($username) public static function usernameToId($username)
{ {
$key = self::CACHE_KEY . 'u2id:' . hash('sha256', $username); $key = self::CACHE_KEY . 'u2id:' . hash('sha256', $username);
return Cache::remember($key, 900, function() use($username) { return Cache::remember($key, 14400, function() use($username) {
$s = Str::of($username); $s = Str::of($username);
if($s->contains('@') && !$s->startsWith('@')) { if($s->contains('@') && !$s->startsWith('@')) {
$username = "@{$username}"; $username = "@{$username}";
@ -220,4 +220,18 @@ class AccountService
return false; return false;
}); });
} }
public static function setLastActive($id = false)
{
if(!$id) { return; }
$key = 'user:last_active_at:id:' . $id;
if(!Cache::has($key)) {
$user = User::find($id);
if(!$user) { return; }
$user->last_active_at = now();
$user->save();
Cache::put($key, 1, 14400);
}
return;
}
} }