mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +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",
|
||||
"version": "2.34.0",
|
||||
"version": "2.34.1",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -14,7 +14,6 @@ import record from '../model/record';
|
||||
import * as contest from '../model/contest';
|
||||
import user from '../model/user';
|
||||
import TaskModel from '../model/task';
|
||||
import paginate from '../lib/paginate';
|
||||
import * as bus from '../service/bus';
|
||||
import {
|
||||
Route, Handler, Connection, ConnectionHandler, Types, param,
|
||||
@@ -62,7 +61,10 @@ class RecordListHandler extends Handler {
|
||||
}
|
||||
let cursor = record.getMulti(domainId, q).sort('_id', -1);
|
||||
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 canViewProblemHidden = (!!tid) || this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
const [udict, pdict] = full ? [{}, {}]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import {
|
||||
ObjectID, Collection, UpdateQuery,
|
||||
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
||||
@@ -232,5 +233,13 @@ bus.on('domain/delete', (domainId) => Promise.all([
|
||||
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;
|
||||
global.Hydro.model.record = RecordModel;
|
||||
Reference in new issue
Block a user