migrate-vijos: support to latest ver

This commit is contained in:
undefined committed 2021-02-24 22:05:32 +08:00
1 parent 77a54b7663
commit 46cb2e31dd
2 files changed
+5 -48

No files matched your search

+2 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/migrate-vijos",
"version": "1.3.9",
"version": "1.4.0",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
@@ -10,14 +10,12 @@
"build": "tsc"
},
"devDependencies": {
"@types/js-yaml": "^4.0.0",
"@types/mongodb": "^3.6.7"
},
"peerDependencies": {
"hydrooj": "2.14.x"
"hydrooj": "^2.17.22"
},
"dependencies": {
"js-yaml": "^4.0.0",
"mongodb": "^3.6.4"
}
}
+3 -44
View File
@@ -1,18 +1,11 @@
/* eslint-disable no-await-in-loop */
// @ts-nocheck
import {
Rdoc, TestCase, Mdoc, Drrdoc, TrainingNode,
} from 'hydrooj';
import fs from 'fs';
import os from 'os';
import path from 'path';
import yaml from 'js-yaml';
import mongodb, { ObjectID, Db, Cursor } from 'mongodb';
import mongodb, { Db, Cursor } from 'mongodb';
const dst = global.Hydro.service.db;
const { file, discussion, document } = global.Hydro.model;
const { testdataConfig } = global.Hydro.lib;
// TODO handle usage_userfile
const { discussion, document } = global.Hydro.model;
// TODO output enhancement
const map = {};
@@ -337,22 +330,6 @@ async function fix(doc) {
{ _id: doc._id },
{ $set: { pid: doc.pid || doc.docId.toString(), content: addSpace(doc.content) } },
);
if (doc.data && doc.data instanceof ObjectID) {
const r = await file.get(doc.data);
const p = path.resolve(os.tmpdir(), 'hydro', `migrate.vijos.${doc._id}.zip`);
const w = fs.createWriteStream(p);
await new Promise((resolve, reject) => {
w.on('finish', resolve);
w.on('error', reject);
r.pipe(w);
});
const config = yaml.load(await testdataConfig.readConfig(p));
await dst.collection('document').updateOne(
{ _id: doc._id },
{ $set: { config } },
);
fs.unlinkSync(p);
}
}
async function fixProblem(report: Function) {
@@ -421,24 +398,6 @@ async function removeInvalidPid(report: Function) {
}
}
async function userfileUsage(src: Db, report: Function) {
const count = await src.collection('domain.user').find().count();
await report({ progress: 1, message: `userfileUsage: ${count}` });
const total = Math.floor(count / 50);
for (let i = 0; i <= total; i++) {
const docs = await src.collection('domain.user')
.find().skip(i * 50).limit(50)
.toArray();
const t = [];
for (const doc of docs) {
if (doc.userfile_usage) {
t.push(dst.collection('user').updateOne({ _id: doc.uid }, { $set: { usage: doc.userfile_usage } }));
}
}
await Promise.all(t);
}
}
async function task(name: any, src: Db, report: Function) {
const count = await cursor[name](src).count();
await report({ progress: 1, message: `${name}: ${count}` });
@@ -550,8 +509,8 @@ export async function run({
await fixProblem(report);
await discussionNode(src, report);
await message(src, report);
await userfileUsage(src, report);
await removeInvalidPid(report);
await global.Hydro.model.system.set('db.ver', 1);
return true;
}