From efb8adfe6d885386e94d32eed53645d298b30be1 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 3 Oct 2022 14:27:59 +0800 Subject: [PATCH] core: remove undocumented domain.union feature --- packages/elastic/index.ts | 2 +- packages/hydrooj/src/handler/user.ts | 2 +- packages/hydrooj/src/interface.ts | 7 ------- packages/hydrooj/src/model/domain.ts | 19 ++----------------- packages/hydrooj/src/model/problem.ts | 5 ++--- packages/hydrooj/src/script/rating.ts | 5 ++--- packages/sonic/index.ts | 8 ++++---- 7 files changed, 12 insertions(+), 36 deletions(-) diff --git a/packages/elastic/index.ts b/packages/elastic/index.ts index d88bc416e..41e5c2ee5 100644 --- a/packages/elastic/index.ts +++ b/packages/elastic/index.ts @@ -26,7 +26,7 @@ global.Hydro.lib.problemSearch = async (domainId, q, opts) => { const allowedSize = SystemModel.get('elasic-search.indexSize') || 10000; const size = opts?.limit || SystemModel.get('pagination.problem'); const from = Math.min(allowedSize - size, opts?.skip || 0); - const union = await DomainModel.getUnion(domainId); + const union = await DomainModel.get(domainId); const domainIds = [domainId, ...(union?.union || [])]; const res = await client.search({ index: 'problem', diff --git a/packages/hydrooj/src/handler/user.ts b/packages/hydrooj/src/handler/user.ts index e629ea262..30ca717a5 100644 --- a/packages/hydrooj/src/handler/user.ts +++ b/packages/hydrooj/src/handler/user.ts @@ -298,7 +298,7 @@ class UserDetailHandler extends Handler { const [udoc, sdoc, union] = await Promise.all([ user.getById(domainId, uid), token.getMostRecentSessionByUid(uid, ['createAt', 'updateAt']), - domain.getUnion(domainId), + domain.get(domainId), ]); if (!udoc) throw new UserNotFoundError(uid); const pdocs: ProblemDoc[] = []; diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index f952dc06a..2edb5e7e7 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -385,12 +385,6 @@ export interface DomainDoc extends Record { host?: string[], } -export interface DomainUnion { - _id: string; - union: string[]; - problem: boolean; -} - // Message export interface MessageDoc { _id: ObjectID, @@ -604,7 +598,6 @@ export interface Collections { 'blacklist': BlacklistDoc; 'domain': DomainDoc; 'domain.user': any; - 'domain.union': DomainUnion; 'record': RecordDoc; 'document': any; 'document.status': StatusDocBase; diff --git a/packages/hydrooj/src/model/domain.ts b/packages/hydrooj/src/model/domain.ts index fd9e9da4d..7aa830ff0 100644 --- a/packages/hydrooj/src/model/domain.ts +++ b/packages/hydrooj/src/model/domain.ts @@ -10,7 +10,6 @@ import UserModel, { deleteUserCache } from './user'; const coll = db.collection('domain'); const collUser = db.collection('domain.user'); -const collUnion = db.collection('domain.union'); interface DomainUserArg { _id: number, @@ -254,23 +253,9 @@ class DomainModel { } @ArgMethod - static async addUnion(domainId: string, union: string[]) { - return await collUnion.updateOne({ _id: domainId }, { $set: { union } }, { upsert: true }); - } - - @ArgMethod - static async removeUnion(domainId: string) { - return await collUnion.deleteOne({ _id: domainId }); - } - - @ArgMethod + /** @deprecated */ static async getUnion(domainId: string) { - return await collUnion.findOne({ _id: domainId }); - } - - @ArgMethod - static async searchUnion(query) { - return await collUnion.find(query).toArray(); + return await coll.findOne({ _id: domainId }); } } diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index f2e9583c1..79d71d9da 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -152,9 +152,8 @@ export class ProblemModel { page: number, pageSize: number, projection = ProblemModel.PROJECTION_LIST, uid?: number, ): Promise<[ProblemDoc[], number, number]> { - const union = await DomainModel.getUnion(domainId); - const domainIds = [domainId]; - if (union?.problem) domainIds.push(...union.union); + const union = await DomainModel.get(domainId); + const domainIds = [domainId, ...(union.union || [])]; let count = 0; const pdocs = []; for (const id of domainIds) { diff --git a/packages/hydrooj/src/script/rating.ts b/packages/hydrooj/src/script/rating.ts index 7a6968681..628b29e70 100644 --- a/packages/hydrooj/src/script/rating.ts +++ b/packages/hydrooj/src/script/rating.ts @@ -137,9 +137,8 @@ export async function calcLevel(domainId: string, report: Function) { } async function runInDomain(id: string, report: Function) { - const info = await domain.getUnion(id); - if (info) info.union.unshift(id); - const domainIds = info ? info.union : [id]; + const info = await domain.get(id); + const domainIds = [id, ...(info.union || [])]; const results: Record = {}; const udict = new Proxy({}, { get: (self, key) => self[key] || 0 }); for (const type in RpTypes) { diff --git a/packages/sonic/index.ts b/packages/sonic/index.ts index b0b94e59b..42916dc11 100644 --- a/packages/sonic/index.ts +++ b/packages/sonic/index.ts @@ -27,7 +27,7 @@ export function apply(ctx: Context) { const cb = async (pdoc) => { i++; if (!(i % 1000)) report({ message: `${i} problems indexed` }); - const union = await DomainModel.searchUnion({ union: pdoc.domainId, problem: true }); + const union = await DomainModel.getMulti({ union: pdoc.domainId }).toArray(); const tasks = []; for (const did of [pdoc.domainId, ...union.map((j) => j._id)]) { tasks.push( @@ -46,7 +46,7 @@ export function apply(ctx: Context) { } ctx.on('problem/add', async (doc, docId) => { - const union = await DomainModel.searchUnion({ union: doc.domainId, problem: true }); + const union = await DomainModel.getMulti({ union: doc.domainId }).toArray(); const tasks = []; for (const domainId of [doc.domainId, ...union.map((i) => i._id)]) { tasks.push( @@ -58,7 +58,7 @@ export function apply(ctx: Context) { }); ctx.on('problem/edit', async (pdoc) => { - const union = await DomainModel.searchUnion({ union: pdoc.domainId, problem: true }); + const union = await DomainModel.getMulti({ union: pdoc.domainId }).toArray(); const tasks = []; const id = `${pdoc.domainId}/${pdoc.docId}`; for (const domainId of [pdoc.domainId, ...union.map((i) => i._id)]) { @@ -73,7 +73,7 @@ export function apply(ctx: Context) { }); ctx.on('problem/del', async (domainId, docId) => { - const union = await DomainModel.searchUnion({ union: domainId, problem: true }); + const union = await DomainModel.getMulti({ union: domainId }).toArray(); const tasks = []; const id = `${domainId}/${docId}`; for (const domain of [domainId, ...union.map((i) => i._id)]) {