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. 10
      models/common.ts
  3. 26
      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", "type": "like-google-fonts",
"url": "https://fonts.loli.net" "url": "https://fonts.loli.net"
}, },
"no_cdn": false "no_cdn": false,
"submissions_page_fast_pagination": false
} }

10
models/common.ts

@ -136,11 +136,11 @@ export default class Model extends TypeORM.BaseEntity {
return queryBuilder.getMany(); 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>, queryBuilder: TypeORM.SelectQueryBuilder<T>,
{ currPageTop, currPageBottom, perPage }, { currPageTop, currPageBottom, perPage },
idOrder: PaginationIDOrder, idOrder: PaginationIDOrder,
pageType: PaginationType) { pageType: PaginationType) {
const queryBuilderBak = queryBuilder.clone(); const queryBuilderBak = queryBuilder.clone();
const result = { const result = {

26
modules/submission.js

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

2
utility.js

@ -245,7 +245,7 @@ module.exports = {
} }
}; };
}, },
paginateLargeData(currPageTop, currPageBottom, perPage) { paginateFast(currPageTop, currPageBottom, perPage) {
function parseIntOrNull(x) { function parseIntOrNull(x) {
if (typeof x === 'string') x = parseInt(x); if (typeof x === 'string') x = parseInt(x);
if (typeof x !== 'number' || isNaN(x)) return null; 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> </div>
<% } else { %> <% } else { %>
<br> <br>
<% include page_largedata %> <% if (fast_pagination) { %>
<% include page_fast %>
<% } else { %>
<% include page %>
<% } %>
<% } %> <% } %>
</div> </div>

Loading…
Cancel
Save