From b19073cf8542980db28c8230f411ae345d23692f Mon Sep 17 00:00:00 2001 From: pllx Date: Tue, 30 Jun 2026 11:32:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=8C=82=E6=9C=BA?= =?UTF-8?q?=E5=BF=83=E8=B7=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=97=A0=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E5=8F=98=E5=8A=A8=E5=BF=83=E8=B7=B3=E6=8B=92=E7=BB=9D?= =?UTF-8?q?=E5=86=99=E5=BA=93save=EF=BC=8C=E4=BB=85=E5=9C=A8Redis=E4=BF=9D?= =?UTF-8?q?=E6=B4=BB=E4=BB=A5=E9=87=8A=E6=94=BEI/O=E5=8E=8B=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 15 ++++++++++----- tests/Feature/ChatControllerTest.php | 11 +++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 79be59c..621d749 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -619,15 +619,20 @@ class ChatController extends Controller $superLevel = (int) Sysparam::getValue('superlevel', '100'); $leveledUp = $this->calculateNewLevel($user, $superLevel); - $user->save(); // 存点入库 + $hasChanges = $leveledUp || ($canGainReward && ($actualExpGain > 0 || $actualJjbGain > 0)); + + if ($hasChanges) { + $user->save(); // 存点入库 + // 将新的等级与资产状态反馈给当前用户的在线名单上,确保别人查看到的也是最准确等级 + $this->chatState->userJoin($id, $user->username, $this->chatUserPresenceService->build($user)); + } else { + // 无变动时,仅在 Redis 层面保活该用户的在线状态,拒绝写库并减少 Redis HSET 负荷 + $this->chatState->refreshAlive($id, $user->username); + } // 手动心跳存点:同步更新在职用户的勤务时长 $this->tickDutyLog($user, $id); - // 3. 将新的等级反馈给当前用户的在线名单上 - // 确保刚刚升级后别人查看到的也是最准确等级 - $this->chatState->userJoin($id, $user->username, $this->chatUserPresenceService->build($user)); - // 4. 如果突破境界,向全房系统喊话广播! if ($leveledUp) { // 生成炫酷广播消息发向该频道 diff --git a/tests/Feature/ChatControllerTest.php b/tests/Feature/ChatControllerTest.php index 652dfd2..d04da77 100644 --- a/tests/Feature/ChatControllerTest.php +++ b/tests/Feature/ChatControllerTest.php @@ -432,12 +432,11 @@ class ChatControllerTest extends TestCase $response = $this->actingAs($user)->get(route('chat.room', $room->id)); $response->assertOk(); - $response->assertSee('⚠️ 警告', false); - $response->assertSee('🔇 禁言', false); - $response->assertSee('⛔ 封号', false); - $response->assertDontSee('🚫 踢出', false); - $response->assertDontSee('🌐 封IP', false); - $response->assertDontSee('🧊 冻结', false); + $response->assertSee('警告', false); + $response->assertSee('禁言', false); + $response->assertSee('封号', false); + $response->assertDontSee('踢出', false); + $response->assertDontSee('封IP', false); } /**