mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 优化record_main查询速度
This commit is contained in:
1 parent
36fa399518
commit
336432cc4f
3 files changed
+14
-3
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.34.0",
|
"version": "2.34.1",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import record from '../model/record';
|
|||||||
import * as contest from '../model/contest';
|
import * as contest from '../model/contest';
|
||||||
import user from '../model/user';
|
import user from '../model/user';
|
||||||
import TaskModel from '../model/task';
|
import TaskModel from '../model/task';
|
||||||
import paginate from '../lib/paginate';
|
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
import {
|
import {
|
||||||
Route, Handler, Connection, ConnectionHandler, Types, param,
|
Route, Handler, Connection, ConnectionHandler, Types, param,
|
||||||
@@ -62,7 +61,10 @@ class RecordListHandler extends Handler {
|
|||||||
}
|
}
|
||||||
let cursor = record.getMulti(domainId, q).sort('_id', -1);
|
let cursor = record.getMulti(domainId, q).sort('_id', -1);
|
||||||
if (!full) cursor = cursor.project(buildProjection(record.PROJECTION_LIST));
|
if (!full) cursor = cursor.project(buildProjection(record.PROJECTION_LIST));
|
||||||
const [rdocs] = invalid ? [[] as RecordDoc[]] : await paginate(cursor, page, full ? 10 : system.get('pagination.record'));
|
const limit = full ? 10 : system.get('pagination.record');
|
||||||
|
const rdocs = invalid
|
||||||
|
? [[] as RecordDoc[]]
|
||||||
|
: await cursor.skip((page - 1) * limit).limit(limit).toArray();
|
||||||
const canViewProblem = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM);
|
const canViewProblem = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM);
|
||||||
const canViewProblemHidden = (!!tid) || this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
const canViewProblemHidden = (!!tid) || this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
const [udict, pdict] = full ? [{}, {}]
|
const [udict, pdict] = full ? [{}, {}]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable object-curly-newline */
|
||||||
import {
|
import {
|
||||||
ObjectID, Collection, UpdateQuery,
|
ObjectID, Collection, UpdateQuery,
|
||||||
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
||||||
@@ -232,5 +233,13 @@ bus.on('domain/delete', (domainId) => Promise.all([
|
|||||||
RecordModel.coll.updateMany({ pdomain: domainId }, { $set: { docId: -1 } }),
|
RecordModel.coll.updateMany({ pdomain: domainId }, { $set: { docId: -1 } }),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
bus.on('app/started', () => {
|
||||||
|
RecordModel.coll.createIndexes([
|
||||||
|
{ key: { 'contest.tid': 1, hidden: 1, _id: -1 }, name: 'basic' },
|
||||||
|
{ key: { 'contest.tid': 1, hidden: 1, uid: 1, _id: -1 }, name: 'withUser' },
|
||||||
|
{ key: { 'contest.tid': 1, hidden: 1, pid: 1, _id: -1 }, name: 'withProblem' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
export default RecordModel;
|
export default RecordModel;
|
||||||
global.Hydro.model.record = RecordModel;
|
global.Hydro.model.record = RecordModel;
|
||||||
Reference in new issue
Block a user