1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Console\Commands;
7
8use App\Models\Chat\Channel;
9use Illuminate\Console\Command;
10use LaravelRedis as Redis;
11
12class ChatExpireAck extends Command
13{
14 protected $signature = 'chat:expire-ack';
15
16 protected $description = 'Cleans up expired chat keep alives.';
17
18 public function handle()
19 {
20 $max = time() - Channel::CHAT_ACTIVITY_TIMEOUT;
21 $this->line("Removing users inactive before {$max}");
22 $progress = $this->output->createProgressBar();
23
24 Channel::public()->select('channel_id')->chunkById(100, function ($chunk) use ($max, $progress) {
25 foreach ($chunk as $channel) {
26 Redis::zremrangebyscore(Channel::getAckKey($channel->getKey()), 0, $max);
27 $progress->advance();
28 }
29 });
30
31 $progress->finish();
32 $this->line('');
33 }
34}