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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,8 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('send:remindMail', ['--force'])->dailyAt('11:30')->onOneServer();
|
||||
// horizon metrics
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes()->onOneServer();
|
||||
// cleanup stale online_count (GC for Redis TTL expiration)
|
||||
$schedule->command('cleanup:online-status')->everyFiveMinutes()->onOneServer();
|
||||
// backup Timing
|
||||
// if (env('ENABLE_AUTO_BACKUP_AND_UPDATE', false)) {
|
||||
// $schedule->command('backup:database', ['true'])->daily()->onOneServer();
|
||||
|
||||
Reference in New Issue
Block a user