perf(server): 复用默认组初始化与批量关系查询

This commit is contained in:
LoveChengke committed 2026-11-07 02:02:11 +08:00
1 parent a0a6b50485
commit 81c96eebaf
6 files changed
+297 -6

No files matched your search

@@ -462,17 +462,21 @@ export async function pushUpdate(
if (devices.length === 0) throw ApiError.badRequest('没有匹配到任何客户端设备');
const results: ClientTargetResult[] = [];
const notBeforeByClass = new Map<string | null, Date>();
for (const device of devices) {
let notBefore: Date | null = null;
if (!clear && input.mode === 'after-school') {
notBefore =
notBeforeByClass.get(device.classId) ?? (await afterSchoolAt(device.classId, input.afterSchoolTime));
notBeforeByClass.set(device.classId, notBefore);
}
await prisma.clientDevice.update({
where: { id: device.id },
data: {
updateTargetVersion: target,
updateProgress: '',
updateMode: clear ? 'idle' : input.mode,
updateNotBefore:
!clear && input.mode === 'after-school'
? await afterSchoolAt(device.classId, input.afterSchoolTime)
: null,
updateNotBefore: notBefore,
},
});
results.push({ deviceId: device.id, deviceName: device.name, ok: true });
@@ -389,9 +389,13 @@ export async function updateGradeLevels(
const byId = new Map(records.map((item) => [item.id, item]));
// 逐条判权限:可能跨多个班级/科目(管理员在成绩页多选修改时会这样)
const checked = new Set<string>();
for (const item of input.items) {
const record = byId.get(item.id)!;
const relation = JSON.stringify([record.classId, record.courseId]);
if (checked.has(relation)) continue;
await assertContentWrite(user, 'grade:write', record.classId, record.courseId, '修改成绩等级');
checked.add(relation);
}
await prisma.$transaction(