core: remove undocumented domain.union feature

This commit is contained in:
undefined committed 2022-10-03 14:27:59 +08:00
1 parent f93108f160
commit efb8adfe6d
7 files changed
+12 -36

No files matched your search

+1 -1
View File
@@ -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',
+1 -1
View File
@@ -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[] = [];
-7
View File
@@ -385,12 +385,6 @@ export interface DomainDoc extends Record<string, any> {
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;
+2 -17
View File
@@ -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 });
}
}
+2 -3
View File
@@ -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) {
+2 -3
View File
@@ -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<keyof typeof RpTypes, ND> = {};
const udict = new Proxy({}, { get: (self, key) => self[key] || 0 });
for (const type in RpTypes) {
+4 -4
View File
@@ -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)]) {