Browse Source

Add option to use the old flexible pagination for submissions page

pull/6/head
Menci 6 years ago
parent
commit
427dc7e118
  1. 3
      config-example.json
  2. 2
      models/common.ts
  3. 22
      modules/submission.js
  4. 2
      utility.js
  5. 0
      views/page_fast.ejs
  6. 6
      views/submissions.ejs

3
config-example.json

@ -123,5 +123,6 @@
"type": "like-google-fonts",
"url": "https://fonts.loli.net"
},
"no_cdn": false
"no_cdn": false,
"submissions_page_fast_pagination": false
}

2
models/common.ts

@ -136,7 +136,7 @@ export default class Model extends TypeORM.BaseEntity {
return queryBuilder.getMany();
}
static async queryPageWithLargeData<T extends TypeORM.BaseEntity>(this: TypeORM.ObjectType<T>,
static async queryPageFast<T extends TypeORM.BaseEntity>(this: TypeORM.ObjectType<T>,
queryBuilder: TypeORM.SelectQueryBuilder<T>,
{ currPageTop, currPageBottom, perPage },
idOrder: PaginationIDOrder,

22
modules/submission.js

@ -103,11 +103,24 @@ app.get('/submissions', async (req, res) => {
isFiltered = true;
}
const queryResult = await JudgeState.queryPageWithLargeData(query, syzoj.utils.paginateLargeData(
let judge_state, paginate;
if (syzoj.config.submissions_page_fast_pagination) {
const queryResult = await JudgeState.queryPageFast(query, syzoj.utils.paginateFast(
req.query.currPageTop, req.query.currPageBottom, syzoj.config.page.judge_state
), -1, parseInt(req.query.page));
const judge_state = queryResult.data;
judge_state = queryResult.data;
paginate = queryResult.meta;
} else {
paginate = syzoj.utils.paginate(
await JudgeState.countQuery(query),
req.query.page,
syzoj.config.page.judge_state
);
judge_state = await JudgeState.queryPage(paginate, query, { id: "DESC" }, true);
}
await judge_state.forEachAsync(async obj => {
await obj.loadRelationships();
if (obj.problem.type !== 'submit-answer') obj.code_length = Buffer.from(obj.code).length;
@ -124,11 +137,12 @@ app.get('/submissions', async (req, res) => {
result: getRoughResult(x, displayConfig, true),
running: false,
})),
paginate: queryResult.meta,
paginate: paginate,
pushType: 'rough',
form: req.query,
displayConfig: displayConfig,
isFiltered: isFiltered
isFiltered: isFiltered,
fast_pagination: syzoj.config.submissions_page_fast_pagination
});
} catch (e) {
syzoj.log(e);

2
utility.js

@ -245,7 +245,7 @@ module.exports = {
}
};
},
paginateLargeData(currPageTop, currPageBottom, perPage) {
paginateFast(currPageTop, currPageBottom, perPage) {
function parseIntOrNull(x) {
if (typeof x === 'string') x = parseInt(x);
if (typeof x !== 'number' || isNaN(x)) return null;

0
views/page_largedata.ejs → views/page_fast.ejs

6
views/submissions.ejs

@ -116,7 +116,11 @@
</div>
<% } else { %>
<br>
<% include page_largedata %>
<% if (fast_pagination) { %>
<% include page_fast %>
<% } else { %>
<% include page %>
<% } %>
<% } %>
</div>

Loading…
Cancel
Save