mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove undocumented domain.union feature
This commit is contained in:
1 parent
f93108f160
commit
efb8adfe6d
7 files changed
+12
-36
No files matched your search
@@ -26,7 +26,7 @@ global.Hydro.lib.problemSearch = async (domainId, q, opts) => {
|
|||||||
const allowedSize = SystemModel.get('elasic-search.indexSize') || 10000;
|
const allowedSize = SystemModel.get('elasic-search.indexSize') || 10000;
|
||||||
const size = opts?.limit || SystemModel.get('pagination.problem');
|
const size = opts?.limit || SystemModel.get('pagination.problem');
|
||||||
const from = Math.min(allowedSize - size, opts?.skip || 0);
|
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 domainIds = [domainId, ...(union?.union || [])];
|
||||||
const res = await client.search({
|
const res = await client.search({
|
||||||
index: 'problem',
|
index: 'problem',
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ class UserDetailHandler extends Handler {
|
|||||||
const [udoc, sdoc, union] = await Promise.all([
|
const [udoc, sdoc, union] = await Promise.all([
|
||||||
user.getById(domainId, uid),
|
user.getById(domainId, uid),
|
||||||
token.getMostRecentSessionByUid(uid, ['createAt', 'updateAt']),
|
token.getMostRecentSessionByUid(uid, ['createAt', 'updateAt']),
|
||||||
domain.getUnion(domainId),
|
domain.get(domainId),
|
||||||
]);
|
]);
|
||||||
if (!udoc) throw new UserNotFoundError(uid);
|
if (!udoc) throw new UserNotFoundError(uid);
|
||||||
const pdocs: ProblemDoc[] = [];
|
const pdocs: ProblemDoc[] = [];
|
||||||
|
|||||||
@@ -385,12 +385,6 @@ export interface DomainDoc extends Record<string, any> {
|
|||||||
host?: string[],
|
host?: string[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DomainUnion {
|
|
||||||
_id: string;
|
|
||||||
union: string[];
|
|
||||||
problem: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Message
|
// Message
|
||||||
export interface MessageDoc {
|
export interface MessageDoc {
|
||||||
_id: ObjectID,
|
_id: ObjectID,
|
||||||
@@ -604,7 +598,6 @@ export interface Collections {
|
|||||||
'blacklist': BlacklistDoc;
|
'blacklist': BlacklistDoc;
|
||||||
'domain': DomainDoc;
|
'domain': DomainDoc;
|
||||||
'domain.user': any;
|
'domain.user': any;
|
||||||
'domain.union': DomainUnion;
|
|
||||||
'record': RecordDoc;
|
'record': RecordDoc;
|
||||||
'document': any;
|
'document': any;
|
||||||
'document.status': StatusDocBase;
|
'document.status': StatusDocBase;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import UserModel, { deleteUserCache } from './user';
|
|||||||
|
|
||||||
const coll = db.collection('domain');
|
const coll = db.collection('domain');
|
||||||
const collUser = db.collection('domain.user');
|
const collUser = db.collection('domain.user');
|
||||||
const collUnion = db.collection('domain.union');
|
|
||||||
|
|
||||||
interface DomainUserArg {
|
interface DomainUserArg {
|
||||||
_id: number,
|
_id: number,
|
||||||
@@ -254,23 +253,9 @@ class DomainModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async addUnion(domainId: string, union: string[]) {
|
/** @deprecated */
|
||||||
return await collUnion.updateOne({ _id: domainId }, { $set: { union } }, { upsert: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
@ArgMethod
|
|
||||||
static async removeUnion(domainId: string) {
|
|
||||||
return await collUnion.deleteOne({ _id: domainId });
|
|
||||||
}
|
|
||||||
|
|
||||||
@ArgMethod
|
|
||||||
static async getUnion(domainId: string) {
|
static async getUnion(domainId: string) {
|
||||||
return await collUnion.findOne({ _id: domainId });
|
return await coll.findOne({ _id: domainId });
|
||||||
}
|
|
||||||
|
|
||||||
@ArgMethod
|
|
||||||
static async searchUnion(query) {
|
|
||||||
return await collUnion.find(query).toArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,9 +152,8 @@ export class ProblemModel {
|
|||||||
page: number, pageSize: number,
|
page: number, pageSize: number,
|
||||||
projection = ProblemModel.PROJECTION_LIST, uid?: number,
|
projection = ProblemModel.PROJECTION_LIST, uid?: number,
|
||||||
): Promise<[ProblemDoc[], number, number]> {
|
): Promise<[ProblemDoc[], number, number]> {
|
||||||
const union = await DomainModel.getUnion(domainId);
|
const union = await DomainModel.get(domainId);
|
||||||
const domainIds = [domainId];
|
const domainIds = [domainId, ...(union.union || [])];
|
||||||
if (union?.problem) domainIds.push(...union.union);
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const pdocs = [];
|
const pdocs = [];
|
||||||
for (const id of domainIds) {
|
for (const id of domainIds) {
|
||||||
|
|||||||
@@ -137,9 +137,8 @@ export async function calcLevel(domainId: string, report: Function) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runInDomain(id: string, report: Function) {
|
async function runInDomain(id: string, report: Function) {
|
||||||
const info = await domain.getUnion(id);
|
const info = await domain.get(id);
|
||||||
if (info) info.union.unshift(id);
|
const domainIds = [id, ...(info.union || [])];
|
||||||
const domainIds = info ? info.union : [id];
|
|
||||||
const results: Record<keyof typeof RpTypes, ND> = {};
|
const results: Record<keyof typeof RpTypes, ND> = {};
|
||||||
const udict = new Proxy({}, { get: (self, key) => self[key] || 0 });
|
const udict = new Proxy({}, { get: (self, key) => self[key] || 0 });
|
||||||
for (const type in RpTypes) {
|
for (const type in RpTypes) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export function apply(ctx: Context) {
|
|||||||
const cb = async (pdoc) => {
|
const cb = async (pdoc) => {
|
||||||
i++;
|
i++;
|
||||||
if (!(i % 1000)) report({ message: `${i} problems indexed` });
|
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 = [];
|
const tasks = [];
|
||||||
for (const did of [pdoc.domainId, ...union.map((j) => j._id)]) {
|
for (const did of [pdoc.domainId, ...union.map((j) => j._id)]) {
|
||||||
tasks.push(
|
tasks.push(
|
||||||
@@ -46,7 +46,7 @@ export function apply(ctx: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.on('problem/add', async (doc, docId) => {
|
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 = [];
|
const tasks = [];
|
||||||
for (const domainId of [doc.domainId, ...union.map((i) => i._id)]) {
|
for (const domainId of [doc.domainId, ...union.map((i) => i._id)]) {
|
||||||
tasks.push(
|
tasks.push(
|
||||||
@@ -58,7 +58,7 @@ export function apply(ctx: Context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ctx.on('problem/edit', async (pdoc) => {
|
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 tasks = [];
|
||||||
const id = `${pdoc.domainId}/${pdoc.docId}`;
|
const id = `${pdoc.domainId}/${pdoc.docId}`;
|
||||||
for (const domainId of [pdoc.domainId, ...union.map((i) => i._id)]) {
|
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) => {
|
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 tasks = [];
|
||||||
const id = `${domainId}/${docId}`;
|
const id = `${domainId}/${docId}`;
|
||||||
for (const domain of [domainId, ...union.map((i) => i._id)]) {
|
for (const domain of [domainId, ...union.map((i) => i._id)]) {
|
||||||
|
|||||||
Reference in new issue
Block a user