mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-29 07:27:26 +08:00
fix: dedup device IPs, reset stale online_count on disconnect and scheduled cleanup (#886)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CleanupOnlineStatus extends Command
|
||||
{
|
||||
protected $signature = 'cleanup:online-status';
|
||||
|
||||
protected $description = 'Reset stale online_count for users whose devices have expired from Redis';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$affected = User::where('online_count', '>', 0)
|
||||
->where(function ($query) {
|
||||
$query->where('last_online_at', '<', now()->subMinutes(10))
|
||||
->orWhereNull('last_online_at');
|
||||
})
|
||||
->update(['online_count' => 0]);
|
||||
|
||||
if ($affected > 0) {
|
||||
$this->info("Reset online_count for {$affected} stale users.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user