mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: add storage calc tool
This commit is contained in:
1 parent
ceea8b5bdd
commit
63bf550311
3 files changed
+43
-1
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.32.12",
|
||||
"version": "2.32.13",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -31,6 +31,7 @@ export const builtinHandler = [
|
||||
|
||||
export const builtinScript = [
|
||||
'rating', 'problemStat', 'blacklist', 'deleteUser', 'updateFilelist',
|
||||
'storageUsage',
|
||||
];
|
||||
|
||||
function getFiles(folder: string, base = ''): string[] {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { STATUS } from '../model/builtin';
|
||||
import storage from '../model/storage';
|
||||
|
||||
export const description = 'Calculate storage usage';
|
||||
|
||||
export async function run(_: {}, report: Function) {
|
||||
const cursor = storage.coll.find({ path: { $regex: /^problem\//i } }).sort({ path: 1 });
|
||||
const count = await cursor.count();
|
||||
report({ message: `Total ${count} files` });
|
||||
let current: string;
|
||||
let memory = 0;
|
||||
let start = new Date().getTime();
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const doc = await cursor.next();
|
||||
const id = doc?.path.split('problem/')[1].split('/')[0]!;
|
||||
if (!current) current = id;
|
||||
if (!doc || current !== id) {
|
||||
const end = new Date().getTime();
|
||||
report({
|
||||
case: {
|
||||
message: current,
|
||||
memory: Math.floor(memory / 102.4) / 10,
|
||||
time: end - start,
|
||||
status: STATUS.STATUS_ACCEPTED,
|
||||
score: 0,
|
||||
},
|
||||
});
|
||||
start = end;
|
||||
memory = 0;
|
||||
current = id;
|
||||
if (!doc) break;
|
||||
}
|
||||
memory += doc.size || 0;
|
||||
}
|
||||
}
|
||||
|
||||
export const validate = {};
|
||||
|
||||
global.Hydro.script.storageUsage = { run, description, validate };
|
||||
Reference in new issue
Block a user