Skip to content

#5312 Fix limit submissions #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: bug-bash
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions src/actions/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,7 @@ import { getService as getChallengesService } from '../services/challenges';
import { getService as getSubmissionService } from '../services/submissions';
import { getApi } from '../services/api';
import * as submissionUtil from '../utils/submission';

const { PAGE_SIZE } = CONFIG;

/**
* Private. Loads from the backend all data matching some conditions.
* @param {Function} getter Given params object of shape { limit, offset }
* loads from the backend at most "limit" data, skipping the first
* "offset" ones. Returns loaded data as an array.
* @param {Number} page Optional. Next page of data to load.
* @param {Number} perPage Optional. The size of the page content to load.
* @param {Array} prev Optional. data loaded so far.
*/
function getAll(getter, page = 1, perPage = PAGE_SIZE, prev) {
/* Amount of submissions to fetch in one API call. 50 is the current maximum
* amount of submissions the backend returns, event when the larger limit is
* explicitely required. */
return getter({
page,
perPage,
}).then((res) => {
if (res.length === 0) {
return prev || res;
}
// parse submissions
let current = [];
if (prev) {
current = prev.concat(res);
} else {
current = res;
}
return getAll(getter, 1 + page, perPage, current);
});
}
import { getAll } from '../utils/tc';

/**
* @static
Expand Down
10 changes: 6 additions & 4 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import qs from 'qs';
import { decodeToken } from '@topcoder-platform/tc-auth-lib';
import logger from '../utils/logger';
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
import { COMPETITION_TRACKS, getAll, getApiResponsePayload } from '../utils/tc';
import { getApi } from './api';
import { getService as getMembersService } from './members';
import { getService as getSubmissionsService } from './submissions';
Expand Down Expand Up @@ -402,12 +402,14 @@ class ChallengesService {
if (memberId) {
isRegistered = _.some(registrants, r => `${r.memberId}` === `${memberId}`);

const subParams = {
const filter = {
challengeId,
perPage: challenge.numOfSubmissions ? challenge.numOfSubmissions : 100,
};

submissions = await this.private.submissionsService.getSubmissions(subParams);
submissions = await getAll(
params => this.private.submissionsService.getSubmissions(filter, params),
1,
);

if (submissions) {
// Remove AV Scan, SonarQube Review and Virus Scan review types
Expand Down
2 changes: 1 addition & 1 deletion src/services/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SubmissionsService {
* @param {Object} params
* @return {Promise} Resolves to the api response.
*/
async getSubmissions(filters, params) {
async getSubmissions(filters, params = {}) {
const query = {
...filters,
...params,
Expand Down
31 changes: 31 additions & 0 deletions src/utils/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,34 @@ export async function getLookerApiResponsePayload(res) {
status: x.status,
};
}

/**
* Private. Loads from the backend all data matching some conditions.
* @param {Function} getter Given params object of shape { limit, offset }
* loads from the backend at most "limit" data, skipping the first
* "offset" ones. Returns loaded data as an array.
* @param {Number} page Optional. Next page of data to load.
* @param {Number} perPage Optional. The size of the page content to load.
* @param {Array} prev Optional. data loaded so far.
*/
export function getAll(getter, page = 1, perPage = 500, prev) {
/* Amount of items to fetch in one API call. 50 is the current maximum
* amount of items the backend returns, event when the larger limit is
* explicitely required. */
return getter({
page,
perPage,
}).then((res) => {
if (res.length === 0) {
return prev || res;
}
// parse items
let current = [];
if (prev) {
current = prev.concat(res);
} else {
current = res;
}
return getAll(getter, 1 + page, perPage, current);
});
}