mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
remove ensureindex api (use postInit instead)
This commit is contained in:
1 parent
be9d2bffb9
commit
e62e7b49a3
13 files changed
+56
-107
No files matched your search
@@ -21,10 +21,9 @@ export function del(ip: string) {
|
||||
return coll.deleteOne({ _id: ip });
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
function ensureIndexes() {
|
||||
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
|
||||
}
|
||||
|
||||
global.Hydro.model.blacklist = {
|
||||
add, get, del, ensureIndexes,
|
||||
};
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.blacklist = { add, get, del };
|
||||
@@ -328,7 +328,7 @@ export async function revSetStatus(
|
||||
return await collStatus.updateOne(filter, update);
|
||||
}
|
||||
|
||||
export async function ensureIndexes() {
|
||||
async function ensureIndexes() {
|
||||
await coll.createIndex({ domainId: 1, docType: 1, docId: 1 }, { unique: true });
|
||||
await coll.createIndex({
|
||||
domainId: 1, docType: 1, owner: 1, docId: -1,
|
||||
@@ -390,6 +390,7 @@ export async function ensureIndexes() {
|
||||
}, { sparse: true });
|
||||
}
|
||||
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.document = {
|
||||
add,
|
||||
addToSet,
|
||||
@@ -399,7 +400,6 @@ global.Hydro.model.document = {
|
||||
deleteMultiStatus,
|
||||
deleteOne,
|
||||
deleteSub,
|
||||
ensureIndexes,
|
||||
get,
|
||||
getMulti,
|
||||
getMultiStatus,
|
||||
|
||||
+3
-2
@@ -135,13 +135,14 @@ export function url(arg0: any, name: any) {
|
||||
return __url(arg0, name);
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
function ensureIndexes() {
|
||||
return Promise.all([
|
||||
collChunk.createIndex({ files_id: 1, n: 1 }, { unique: true }),
|
||||
collFile.createIndex({ md5: 1 }),
|
||||
]);
|
||||
}
|
||||
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.file = {
|
||||
add, get, del, inc, dec, getMeta, getWithSecret, getMulti, getMetaDict, url, ensureIndexes,
|
||||
add, get, del, inc, dec, getMeta, getWithSecret, getMulti, getMetaDict, url,
|
||||
};
|
||||
@@ -62,13 +62,14 @@ export function getMulti(uid: number) {
|
||||
return coll.find({ $or: [{ from: uid }, { to: uid }] });
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
function ensureIndexes() {
|
||||
return Promise.all([
|
||||
coll.createIndex({ to: 1, _id: -1 }),
|
||||
coll.createIndex({ from: 1, _id: -1 }),
|
||||
]);
|
||||
}
|
||||
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.message = {
|
||||
FLAG_UNREAD,
|
||||
FLAG_ALERT,
|
||||
@@ -81,5 +82,4 @@ global.Hydro.model.message = {
|
||||
getMany,
|
||||
getMulti,
|
||||
send,
|
||||
ensureIndexes,
|
||||
};
|
||||
@@ -19,8 +19,9 @@ export async function inc(op: string, ident: string, periodSecs: number, maxOper
|
||||
}
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
function ensureIndexes() {
|
||||
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
|
||||
}
|
||||
|
||||
global.Hydro.model.opcount = { inc, ensureIndexes };
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.opcount = { inc };
|
||||
+3
-17
@@ -80,31 +80,17 @@ export async function add(
|
||||
rejudged: false,
|
||||
};
|
||||
if ((contestOrConfig as ContestInfo).type) {
|
||||
// is contest
|
||||
data.contest = contestOrConfig as ContestInfo;
|
||||
} else {
|
||||
data.config = contestOrConfig as PretestConfig;
|
||||
}
|
||||
const [pdoc, res] = await Promise.all([
|
||||
problem.get(domainId, pid, null),
|
||||
coll.insertOne(data),
|
||||
]);
|
||||
const res = await coll.insertOne(data);
|
||||
if (addTask) {
|
||||
const t: any = {
|
||||
await task.add({
|
||||
type: 'judge',
|
||||
rid: res.insertedId,
|
||||
domainId,
|
||||
pid: data.pid,
|
||||
lang: data.lang,
|
||||
code: data.code,
|
||||
};
|
||||
if (t.type === 'judge') {
|
||||
t.data = pdoc.data;
|
||||
t.config = pdoc.config;
|
||||
} else {
|
||||
t.config = yaml.safeDump(contestOrConfig);
|
||||
}
|
||||
await task.add(t);
|
||||
});
|
||||
}
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export const TYPE_CHANGEMAIL = 3;
|
||||
export const TYPE_OAUTH = 4;
|
||||
export const TYPE_LOSTPASS = 5;
|
||||
|
||||
export function ensureIndexes() {
|
||||
function ensureIndexes() {
|
||||
return Promise.all([
|
||||
coll.createIndex([{ uid: 1 }, { tokenType: 1 }, { updateAt: -1 }], { sparse: true }),
|
||||
coll.createIndex('expireAt', { expireAfterSeconds: 0 }),
|
||||
@@ -31,9 +31,8 @@ export async function add(tokenType: number, expireSeconds: number, data: any) {
|
||||
return [str, res.ops[0]];
|
||||
}
|
||||
|
||||
export async function get(tokenId: string, tokenType: number, doThrow = true) {
|
||||
export async function get(tokenId: string, tokenType: number) {
|
||||
const res = await coll.findOne({ _id: tokenId, tokenType });
|
||||
if (!res && doThrow) throw new ValidationError('token');
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -86,6 +85,7 @@ export function delByUid(uid: number) {
|
||||
return coll.deleteMany({ uid });
|
||||
}
|
||||
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.token = {
|
||||
TYPE_SESSION,
|
||||
TYPE_CHANGEMAIL,
|
||||
@@ -94,7 +94,6 @@ global.Hydro.model.token = {
|
||||
TYPE_REGISTRATION,
|
||||
TYPE_LOSTPASS,
|
||||
|
||||
ensureIndexes,
|
||||
add,
|
||||
createOrUpdate,
|
||||
get,
|
||||
|
||||
+12
-6
@@ -85,12 +85,18 @@ export class User implements _User {
|
||||
}
|
||||
}
|
||||
|
||||
hasPerm(p: bigint) {
|
||||
return (this.perm() & p) === p;
|
||||
hasPerm(...perm: bigint[]) {
|
||||
for (const i in perm) {
|
||||
if ((this.perm() & perm[i]) === perm[i]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
hasPriv(p: number) {
|
||||
return !!(this.priv & p);
|
||||
hasPriv(...priv: number[]) {
|
||||
for (const i in priv) {
|
||||
if ((this.priv & priv[i]) === priv[i]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
checkPassword(password: string) {
|
||||
@@ -215,13 +221,14 @@ export function ban(uid: number) {
|
||||
]);
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
function ensureIndexes() {
|
||||
return Promise.all([
|
||||
coll.createIndex('unameLower', { unique: true }),
|
||||
coll.createIndex('mailLower', { sparse: true }),
|
||||
]);
|
||||
}
|
||||
|
||||
global.Hydro.postInit.push(ensureIndexes);
|
||||
global.Hydro.model.user = {
|
||||
User,
|
||||
create,
|
||||
@@ -237,5 +244,4 @@ global.Hydro.model.user = {
|
||||
setPriv,
|
||||
getList,
|
||||
ban,
|
||||
ensureIndexes,
|
||||
};
|
||||
Reference in new issue
Block a user