Explorar o código

fix superball_daily更新卡顿

laowu hai 1 día
pai
achega
1d3d9fe047
Modificáronse 1 ficheiros con 8 adicións e 12 borrados
  1. 8 12
      app/Services/SuperballActivityService.php

+ 8 - 12
app/Services/SuperballActivityService.php

@@ -258,19 +258,15 @@ class SuperballActivityService
                 ->where('task_date', $today)
                 ->update(['status' => 1, 'updated_at' => now()->format('Y-m-d H:i:s')]);
 
-            $daily = DB::connection('write')->table(TableName::agent() . 'superball_daily')
+            // Perform atomic increments in a single query to avoid holding an explicit row lock via SELECT ... FOR UPDATE.
+            // This is safe because we only increment if the record already exists (same behavior as before).
+            DB::connection('write')->table(TableName::agent() . 'superball_daily')
                 ->where('pool_date', $today)
-                ->lockForUpdate()
-                ->first();
-            if ($daily) {
-                DB::connection('write')->table(TableName::agent() . 'superball_daily')
-                    ->where('pool_date', $today)
-                    ->update([
-                        'total_balls' => (int) $daily->total_balls + $ballCount,
-                        'completed_count' => (int) $daily->completed_count + 1,
-                        'updated_at' => now()->format('Y-m-d H:i:s'),
-                    ]);
-            }
+                ->update([
+                    'total_balls' => DB::raw("total_balls + {$ballCount}"),
+                    'completed_count' => DB::raw('completed_count + 1'),
+                    'updated_at' => now()->format('Y-m-d H:i:s'),
+                ]);
 
             $this->updateUserMultiplier($userId, $today);
         });