Skip to content

Commit

Permalink
Add option to use the old flexible pagination for submissions page
Browse files Browse the repository at this point in the history
  • Loading branch information
Menci committed Apr 28, 2019
1 parent 1522847 commit 427dc7e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@
"type": "like-google-fonts",
"url": "https://fonts.loli.net"
},
"no_cdn": false
"no_cdn": false,
"submissions_page_fast_pagination": false
}
10 changes: 5 additions & 5 deletions models/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export default class Model extends TypeORM.BaseEntity {
return queryBuilder.getMany();
}

static async queryPageWithLargeData<T extends TypeORM.BaseEntity>(this: TypeORM.ObjectType<T>,
queryBuilder: TypeORM.SelectQueryBuilder<T>,
{ currPageTop, currPageBottom, perPage },
idOrder: PaginationIDOrder,
pageType: PaginationType) {
static async queryPageFast<T extends TypeORM.BaseEntity>(this: TypeORM.ObjectType<T>,
queryBuilder: TypeORM.SelectQueryBuilder<T>,
{ currPageTop, currPageBottom, perPage },
idOrder: PaginationIDOrder,
pageType: PaginationType) {
const queryBuilderBak = queryBuilder.clone();

const result = {
Expand Down
26 changes: 20 additions & 6 deletions modules/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,24 @@ app.get('/submissions', async (req, res) => {
isFiltered = true;
}

const queryResult = await JudgeState.queryPageWithLargeData(query, syzoj.utils.paginateLargeData(
req.query.currPageTop, req.query.currPageBottom, syzoj.config.page.judge_state
), -1, parseInt(req.query.page));
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));

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 obj.loadRelationships();
if (obj.problem.type !== 'submit-answer') obj.code_length = Buffer.from(obj.code).length;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion views/submissions.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@
</div>
<% } else { %>
<br>
<% include page_largedata %>
<% if (fast_pagination) { %>
<% include page_fast %>
<% } else { %>
<% include page %>
<% } %>
<% } %>
</div>

Expand Down

0 comments on commit 427dc7e

Please sign in to comment.