1.优化游戏实时对局/admin/game/live页面卡顿的问题
This commit is contained in:
@@ -104,7 +104,7 @@ final class GameHotDataRedis
|
||||
}
|
||||
|
||||
/**
|
||||
* 对局写入后:刷新指定 id 的行缓存,并删除「活跃局 / 最新局」聚合键以免脏读
|
||||
* 对局写入后:刷新指定 id 行缓存,并回写「活跃局 / 最新局」聚合键(供 snapshot / WS 只读 Redis)
|
||||
*
|
||||
* @param int|null $id 可为 null(仅清聚合键)
|
||||
*/
|
||||
@@ -122,7 +122,33 @@ final class GameHotDataRedis
|
||||
self::redisDel(self::KEY_GR_ID . $id);
|
||||
}
|
||||
}
|
||||
self::redisDel(self::KEY_GR_ACTIVE, self::KEY_GR_LATEST);
|
||||
self::gameRecordRefreshAggregateCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入后回写「活跃局 / 最新局」聚合缓存(读库一次,供 snapshot / WS 直推只读 Redis)。
|
||||
*/
|
||||
public static function gameRecordRefreshAggregateCaches(): void
|
||||
{
|
||||
if (!self::enabled()) {
|
||||
return;
|
||||
}
|
||||
$ttl = self::intConfig('ttl_game_record', 60);
|
||||
$active = Db::name('game_record')
|
||||
->whereIn('status', [0, 1, 2, 3])
|
||||
->order('id', 'desc')
|
||||
->find();
|
||||
if (is_array($active)) {
|
||||
self::redisSetEx(self::KEY_GR_ACTIVE, $ttl, json_encode($active, JSON_UNESCAPED_UNICODE));
|
||||
} else {
|
||||
self::redisDel(self::KEY_GR_ACTIVE);
|
||||
}
|
||||
$latest = Db::name('game_record')->order('id', 'desc')->find();
|
||||
if (is_array($latest)) {
|
||||
self::redisSetEx(self::KEY_GR_LATEST, $ttl, json_encode($latest, JSON_UNESCAPED_UNICODE));
|
||||
} else {
|
||||
self::redisDel(self::KEY_GR_LATEST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user