mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core&ui: remove static manifest
This commit is contained in:
1 parent
10c3a62168
commit
d7412fcc1e
18 files changed
+50
-124
No files matched your search
@@ -148,19 +148,6 @@ export async function template(pending: string[], fail: string[]) {
|
||||
await bus.serial('app/load/template');
|
||||
}
|
||||
|
||||
export async function uistatic(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'public', 'static-manifest.json');
|
||||
if (fs.existsSync(p) && fs.statSync(p).isFile() && !fail.includes(i)) {
|
||||
try {
|
||||
Object.assign(global.Hydro.ui.manifest, eval('require')(p));
|
||||
} catch (e) {
|
||||
fail.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function model(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
let p = path.resolve(i, 'model.ts');
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as bus from '../service/bus';
|
||||
import db from '../service/db';
|
||||
import {
|
||||
builtinHandler, builtinLib, builtinModel,
|
||||
builtinScript, handler, lib, locale, model, script, service, setting, template, uistatic,
|
||||
builtinScript, handler, lib, locale, model, script, service, setting, template,
|
||||
} from './common';
|
||||
|
||||
const logger = new Logger('worker');
|
||||
@@ -34,7 +34,6 @@ export async function load() {
|
||||
await Promise.all([
|
||||
locale(pending, fail),
|
||||
template(pending, fail),
|
||||
uistatic(pending, fail),
|
||||
]);
|
||||
if (detail) logger.info('finish: locale/template/static');
|
||||
const opts = options();
|
||||
|
||||
@@ -30,7 +30,17 @@ export function addon(addonPath: string, prepend = false) {
|
||||
const packagejson = require.resolve(`${addonPath}/package.json`);
|
||||
const modulePath = path.dirname(packagejson);
|
||||
const publicPath = path.resolve(modulePath, 'public');
|
||||
if (fs.existsSync(publicPath)) global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
|
||||
if (fs.existsSync(publicPath)) {
|
||||
global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
|
||||
const targets = fs.readdirSync(publicPath);
|
||||
for (const target of targets) {
|
||||
if (global.ui.manifest[target] && !prepend) {
|
||||
global.ui.manifest[target] = publicPath;
|
||||
} else if (!global.staticFiles[target]) {
|
||||
global.ui.manifest[target] = publicPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
global.addons[prepend ? 'unshift' : 'push'](modulePath);
|
||||
} catch (e) {
|
||||
logger.error(`Addon not found: ${addonPath}`);
|
||||
|
||||
@@ -103,7 +103,9 @@ class DomainModel {
|
||||
static async getList(domainIds: string[]) {
|
||||
const r: Record<string, DomainDoc | null> = {};
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const domainId of domainIds) r[domainId] = await DomainModel.get(domainId);
|
||||
const tasks = [];
|
||||
for (const domainId of domainIds) tasks.push(DomainModel.get(domainId).then((ddoc) => { r[domainId] = ddoc; }));
|
||||
await Promise.all(tasks);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,25 +23,16 @@ async function runProblem(...arg: any[]) {
|
||||
? await problem.get(arg[0], arg[1])
|
||||
: arg[0];
|
||||
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
||||
const [, nPages] = await paginate(
|
||||
problem.getMultiStatus(
|
||||
const nPages = Math.floor(
|
||||
(await problem.getMultiStatus(
|
||||
pdoc.domainId, { docId: pdoc.docId, rid: { $ne: null } },
|
||||
),
|
||||
1,
|
||||
100,
|
||||
).count() + 99) / 100,
|
||||
);
|
||||
const nAccept = await problem.getMultiStatus(
|
||||
pdoc.domainId, { docId: pdoc.docId, status: STATUS.STATUS_ACCEPTED },
|
||||
).count();
|
||||
const p = (pdoc.difficulty || 5) / (Math.sqrt(Math.sqrt(nAccept)) + 1);
|
||||
const p = (pdoc.difficulty || 5) / (Math.sqrt(Math.sqrt(pdoc.nAccept)) + 1);
|
||||
for (let page = 1; page <= nPages; page++) {
|
||||
const [psdocs] = await paginate(
|
||||
problem.getMultiStatus(
|
||||
pdoc.domainId, { docId: pdoc.docId, rid: { $ne: null } },
|
||||
),
|
||||
page,
|
||||
100,
|
||||
) as any[][];
|
||||
const psdocs = await problem.getMultiStatus(
|
||||
pdoc.domainId, { docId: pdoc.docId, rid: { $ne: null } },
|
||||
).limit(100).skip((page - 1) * 100).project({ rid: 1 }).toArray();
|
||||
const rdict = await record.getList(pdoc.domainId, psdocs.map((psdoc) => psdoc.rid), true);
|
||||
for (const psdoc of psdocs) {
|
||||
if (rdict[psdoc.rid.toHexString()]) {
|
||||
@@ -95,8 +86,10 @@ export async function calcLevel(domainId: string, report: Function) {
|
||||
const coll = db.collection('domain.user');
|
||||
const ducur = domain.getMultiUserInDomain(domainId, filter).project({ rp: 1 }).sort({ rp: -1 });
|
||||
let bulk = coll.initializeUnorderedBulkOp();
|
||||
while (await ducur.hasNext()) {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const dudoc = await ducur.next();
|
||||
if (!dudoc) break;
|
||||
if ([0, 1].includes(dudoc.uid)) continue;
|
||||
count++;
|
||||
if (!dudoc.rp) dudoc.rp = null;
|
||||
@@ -130,18 +123,6 @@ async function runInDomain(id: string, isSub: boolean, report: Function) {
|
||||
...await domain.getMultiUserInDomain('', { domainId }).toArray(),
|
||||
], (a, b) => a.uid === b.uid);
|
||||
for (const dudoc of dudocs) deltaudict[dudoc.uid] = dudoc.rpdelta;
|
||||
const contests: Tdoc<30 | 60>[] = await contest.getMulti('', { domainId, rated: true })
|
||||
.toArray() as any;
|
||||
await report({ message: `Found ${contests.length} contests in ${id}` });
|
||||
for (const i in contests) {
|
||||
const tdoc = contests[i];
|
||||
await runContest(tdoc, udict, report);
|
||||
if (!isSub) {
|
||||
await report({
|
||||
progress: Math.floor(((parseInt(i, 10) + 1) / contests.length) * 100),
|
||||
});
|
||||
}
|
||||
}
|
||||
// TODO pagination
|
||||
const problems = await problem.getMulti('', { domainId, hidden: false }).toArray();
|
||||
await report({ message: `Found ${problems.length} problems in ${id}` });
|
||||
@@ -150,7 +131,19 @@ async function runInDomain(id: string, isSub: boolean, report: Function) {
|
||||
await runProblem(pdoc, udict);
|
||||
if (!isSub) {
|
||||
await report({
|
||||
progress: Math.floor(((parseInt(i, 10) + 1) / problems.length) * 100),
|
||||
progress: Math.floor(((+i + 1) / problems.length) * 100),
|
||||
});
|
||||
}
|
||||
}
|
||||
const contests: Tdoc<30 | 60>[] = await contest.getMulti('', { domainId, rated: true })
|
||||
.toArray() as any;
|
||||
await report({ message: `Found ${contests.length} contests in ${id}` });
|
||||
for (const i in contests) {
|
||||
const tdoc = contests[i];
|
||||
await runContest(tdoc, udict, report);
|
||||
if (!isSub) {
|
||||
await report({
|
||||
progress: Math.floor(((+i + 1) / contests.length) * 100),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -182,7 +175,7 @@ export async function run({ domainId }, report: Function) {
|
||||
memory: 0,
|
||||
score: 0,
|
||||
},
|
||||
progress: Math.floor(((parseInt(i, 10) + 1) / domains.length) * 100),
|
||||
progress: Math.floor(((+i + 1) / domains.length) * 100),
|
||||
});
|
||||
}
|
||||
} else await runInDomain(domainId, false, report);
|
||||
|
||||
@@ -309,7 +309,7 @@ export class HandlerCommon {
|
||||
}
|
||||
|
||||
renderTitle(str: string) {
|
||||
const name = this.domain.ui?.name || system.get('server.name');
|
||||
const name = this.domain?.ui?.name || system.get('server.name');
|
||||
if (this.extraTitleContent) return `${this.translate(str)} - ${this.extraTitleContent} - ${name}`;
|
||||
return `${this.translate(str)} - ${name}`;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ const scripts: UpgradeScript[] = [
|
||||
await document.getMulti(d._id, document.TYPE_DISCUSSION_REPLY).forEach((drdoc) => {
|
||||
bulk.find({ _id: drdoc._id }).updateOne({ $set: { history: [] } });
|
||||
});
|
||||
// TODO tail reply
|
||||
await document.getMulti(d._id, document.TYPE_PROBLEM_SOLUTION).forEach((psdoc) => {
|
||||
bulk.find({ _id: psdoc._id }).updateOne({ $set: { history: [] } });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user