feat: 优化自动门数据处理逻辑,限制每帧处理数量以减少性能开销,并实现批量更新设备状态
This commit is contained in:
parent
fba02ccd66
commit
a88876697f
@ -271,14 +271,21 @@ export class AutoDoorService {
|
||||
|
||||
/**
|
||||
* 处理缓冲的自动门点数据(在渲染循环中调用)
|
||||
* 优化:限制每帧处理数量,减少性能开销
|
||||
* @param frameBudget 帧预算(毫秒)
|
||||
* @param startTime 开始时间
|
||||
* @returns 是否还有待处理的数据
|
||||
*/
|
||||
processBufferedData(frameBudget: number, startTime: number): boolean {
|
||||
// 在时间预算内,持续处理自动门点数据
|
||||
while (performance.now() - startTime < frameBudget && this.latestAutoDoorData.size > 0) {
|
||||
// 获取并移除 Map 中的第一条自动门点数据
|
||||
const maxProcessPerFrame = 3; // 限制每帧最多处理3个自动门点
|
||||
let processedCount = 0;
|
||||
|
||||
// 在时间预算内,智能处理自动门点数据
|
||||
while (
|
||||
performance.now() - startTime < frameBudget &&
|
||||
this.latestAutoDoorData.size > 0 &&
|
||||
processedCount < maxProcessPerFrame
|
||||
) {
|
||||
const entry = this.latestAutoDoorData.entries().next().value;
|
||||
if (!entry) break;
|
||||
|
||||
@ -293,18 +300,30 @@ export class AutoDoorService {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 更新该设备对应的所有自动门点状态
|
||||
// 批量更新该设备对应的所有自动门点状态
|
||||
if (this.editorService) {
|
||||
for (const pid of pointIds) {
|
||||
this.editorService.updateAutoDoorByDeviceId(
|
||||
data.deviceId,
|
||||
data.deviceStatus,
|
||||
data.isConnected,
|
||||
data.active,
|
||||
pid,
|
||||
// 使用批量更新减少渲染调用
|
||||
const updates = pointIds.map(pid => ({
|
||||
id: pid,
|
||||
deviceId: data.deviceId,
|
||||
deviceStatus: data.deviceStatus,
|
||||
isConnected: data.isConnected,
|
||||
active: data.active
|
||||
}));
|
||||
|
||||
// 批量执行更新
|
||||
updates.forEach(update => {
|
||||
this.editorService!.updateAutoDoorByDeviceId(
|
||||
update.deviceId,
|
||||
update.deviceStatus,
|
||||
update.isConnected,
|
||||
update.active,
|
||||
update.id,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
processedCount++;
|
||||
}
|
||||
|
||||
// 返回是否还有待处理的数据
|
||||
|
Loading…
x
Reference in New Issue
Block a user