From 1bdd03220d3c52133b1d6ff3dca446353f5b572c Mon Sep 17 00:00:00 2001 From: panda Date: Tue, 19 Sep 2023 17:09:00 +0000 Subject: [PATCH] core: fix contest vnode id is not a ObjectId --- packages/hydrooj/src/model/discussion.ts | 2 +- packages/hydrooj/src/upgrade.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/hydrooj/src/model/discussion.ts b/packages/hydrooj/src/model/discussion.ts index 6ee3d34c9..c0eba89a6 100644 --- a/packages/hydrooj/src/model/discussion.ts +++ b/packages/hydrooj/src/model/discussion.ts @@ -288,7 +288,7 @@ export async function getVnode(domainId: string, type: number, id: string, uid?: tdoc.attend = tsdoc?.attend || tsdoc?.enroll; } return { - ...tdoc, type, id, hidden: false, + ...tdoc, type, id: _id, hidden: false, }; } return { diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index bbcbcccbe..037d1ac74 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -616,6 +616,18 @@ const scripts: UpgradeScript[] = [ } return true; }, + async function _84_85() { + return await iterateAllDomain(async ({ _id }) => { + const cursor = discussion.getMulti(_id, { parentType: document.TYPE_CONTEST }); + for await (const ddoc of cursor) { + try { + await contest.get(_id, ddoc.parentId as ObjectId); + } catch (e) { + await discussion.del(_id, ddoc.docId); + } + } + }); + }, ]; export default scripts;