|
|
@ -13,6 +13,7 @@ import { BasicProvider, IBasicProvider, RemoteAccount } from './interface';
|
|
|
|
const coll = db.collection('vjudge');
|
|
|
|
const coll = db.collection('vjudge');
|
|
|
|
const Pool = {};
|
|
|
|
const Pool = {};
|
|
|
|
const logger = new Logger('vjudge');
|
|
|
|
const logger = new Logger('vjudge');
|
|
|
|
|
|
|
|
const syncing = {};
|
|
|
|
|
|
|
|
|
|
|
|
class Service {
|
|
|
|
class Service {
|
|
|
|
api: IBasicProvider;
|
|
|
|
api: IBasicProvider;
|
|
|
@ -37,7 +38,9 @@ class Service {
|
|
|
|
while (pids.length) {
|
|
|
|
while (pids.length) {
|
|
|
|
logger.info(`${domainId}: Syncing page ${page}`);
|
|
|
|
logger.info(`${domainId}: Syncing page ${page}`);
|
|
|
|
for (const pid of pids) {
|
|
|
|
for (const pid of pids) {
|
|
|
|
if (await ProblemModel.get(domainId, pid)) continue;
|
|
|
|
if (syncing[`${domainId}/${pid}`] || await ProblemModel.get(domainId, pid)) continue;
|
|
|
|
|
|
|
|
syncing[`${domainId}/${pid}`] = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const res = await this.api.getProblem(pid);
|
|
|
|
const res = await this.api.getProblem(pid);
|
|
|
|
if (!res) continue;
|
|
|
|
if (!res) continue;
|
|
|
|
const id = await ProblemModel.add(domainId, pid, res.title, res.content, 1, res.tag, false);
|
|
|
|
const id = await ProblemModel.add(domainId, pid, res.title, res.content, 1, res.tag, false);
|
|
|
@ -48,6 +51,9 @@ class Service {
|
|
|
|
await ProblemModel.addTestdata(domainId, id, key, res.data[key]);
|
|
|
|
await ProblemModel.addTestdata(domainId, id, key, res.data[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.info(`${domainId}: problem ${id} sync done`);
|
|
|
|
logger.info(`${domainId}: problem ${id} sync done`);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
delete syncing[`${domainId}/${pid}`];
|
|
|
|
|
|
|
|
}
|
|
|
|
await sleep(5000);
|
|
|
|
await sleep(5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page++;
|
|
|
|
page++;
|
|
|
|