mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: 测试数据添加_id便于索引
This commit is contained in:
1 parent
545906d3d3
commit
7799e1fed7
2 files changed
+27
-3
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.17.14",
|
"version": "2.17.15",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -27,8 +27,14 @@ async function iterateAllDomain(cb: (ddoc: DomainDoc, current?: number, total?:
|
|||||||
|
|
||||||
async function iterateAllProblem(fields: problem.Pdoc.Field[], cb: (pdoc: problem.Pdoc, current?: number, total?: number) => Promise<any>) {
|
async function iterateAllProblem(fields: problem.Pdoc.Field[], cb: (pdoc: problem.Pdoc, current?: number, total?: number) => Promise<any>) {
|
||||||
await iterateAllDomain(async (d) => {
|
await iterateAllDomain(async (d) => {
|
||||||
const pdocs = await problem.getMulti(d._id, {}, fields).toArray();
|
const cursor = problem.getMulti(d._id, {}, fields);
|
||||||
for (const i in pdocs) await cb(pdocs[i], +i, pdocs.length);
|
const total = await problem.getMulti(d._id, {}).count();
|
||||||
|
let i = 0;
|
||||||
|
while (await cursor.hasNext()) {
|
||||||
|
const doc = await cursor.next();
|
||||||
|
i++;
|
||||||
|
await cb(doc, i, total);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +160,24 @@ const scripts: UpgradeScript[] = [
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
async function _8_9() {
|
||||||
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
|
await iterateAllProblem(['docId', 'domainId'], async (pdoc) => {
|
||||||
|
logger.info('%s/%s', pdoc.domainId, pdoc.docId);
|
||||||
|
const [data, additional_file] = await Promise.all([
|
||||||
|
storage.list(`problem/${pdoc.domainId}/${pdoc.docId}/testdata/`),
|
||||||
|
storage.list(`problem/${pdoc.domainId}/${pdoc.docId}/additional_files/`),
|
||||||
|
]) as any;
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
data[i]._id = data[i].name;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < additional_file.length; i++) {
|
||||||
|
additional_file[i]._id = additional_file[i].name;
|
||||||
|
}
|
||||||
|
await problem.edit(pdoc.domainId, pdoc.docId, { data, additional_file });
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export = scripts;
|
export = scripts;
|
||||||
Reference in new issue
Block a user