fix stat_user unique key with record_type and deduplicate before index

This commit is contained in:
yinjianm
2026-02-26 04:39:42 +08:00
parent 87e547d2f1
commit 1e291f8408
2 changed files with 44 additions and 4 deletions
+2 -2
View File
@@ -129,7 +129,7 @@ class StatUserJob implements ShouldQueue
'created_at' => time(),
'updated_at' => time(),
],
['user_id', 'server_rate', 'server_id', 'server_type', 'record_at'],
['user_id', 'server_rate', 'server_id', 'server_type', 'record_at', 'record_type'],
[
'u' => DB::raw("u + VALUES(u)"),
'd' => DB::raw("d + VALUES(d)"),
@@ -152,7 +152,7 @@ class StatUserJob implements ShouldQueue
$sql = "INSERT INTO {$table} (user_id, server_rate, server_id, server_type, record_at, record_type, u, d, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (user_id, server_rate, server_id, server_type, record_at)
ON CONFLICT (user_id, server_rate, server_id, server_type, record_at, record_type)
DO UPDATE SET
u = {$table}.u + EXCLUDED.u,
d = {$table}.d + EXCLUDED.d,