Browse Source

Fix query submissions too slow

pull/6/head
Menci 6 years ago
parent
commit
7aeafe3c95
  1. 7
      models/common.ts
  2. 2
      modules/submission.js

7
models/common.ts

@ -30,7 +30,7 @@ export default class Model extends TypeORM.BaseEntity {
return await queryBuilder.getMany();
}
static async queryPage(paginater: Paginater, where, order) {
static async queryPage(paginater: Paginater, where, order, largeData) {
if (!paginater.pageCnt) return [];
let queryBuilder = where instanceof TypeORM.SelectQueryBuilder
@ -42,6 +42,11 @@ export default class Model extends TypeORM.BaseEntity {
queryBuilder = queryBuilder.skip((paginater.currPage - 1) * paginater.perPage)
.take(paginater.perPage);
if (largeData) {
const rawResult = await queryBuilder.select('id').getRawMany();
return await Promise.all(rawResult.map(async result => this.findById(result.id)));
}
return queryBuilder.getMany();
}

2
modules/submission.js

@ -104,7 +104,7 @@ app.get('/submissions', async (req, res) => {
}
let paginate = syzoj.utils.paginate(await JudgeState.countQuery(query), req.query.page, syzoj.config.page.judge_state);
let judge_state = await JudgeState.queryPage(paginate, query, { id: "DESC" });
let judge_state = await JudgeState.queryPage(paginate, query, { id: "DESC" }, true);
await judge_state.forEachAsync(async obj => {
await obj.loadRelationships();

Loading…
Cancel
Save