Skip to content

Commit

Permalink
Limit max number of submissions in a batch_show.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanzdosilovic committed Jan 17, 2020
1 parent 04c900c commit cb676d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def show

def batch_show
tokens = (request.headers[:tokens] || params[:tokens]).to_s.strip.split(",")

if tokens.length > Config::MAX_SUBMISSION_BATCH_SIZE
render json: {
error: "number of submissions in a batch should be less than or equal to #{Config::MAX_SUBMISSION_BATCH_SIZE}"
}, status: :bad_request
return
elsif tokens.length == 0
render json: {
error: "there should be at least one submission in a batch"
}, status: :bad_request
return
end

existing_submissions = Hash[Submission.where(token: tokens).collect{ |s| [s.token, s] }]

submissions = []
Expand Down Expand Up @@ -107,12 +120,12 @@ def batch_create

if number_of_submissions > Config::MAX_SUBMISSION_BATCH_SIZE
render json: {
error: "number of submissions in batch create should be less than or equal to #{Config::MAX_SUBMISSION_BATCH_SIZE}"
error: "number of submissions in a batch should be less than or equal to #{Config::MAX_SUBMISSION_BATCH_SIZE}"
}, status: :bad_request
return
elsif number_of_submissions == 0
render json: {
error: "there should be at least one submission in batch create"
error: "there should be at least one submission in a batch"
}, status: :bad_request
return
end
Expand Down
2 changes: 1 addition & 1 deletion judge0-api.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,6 @@ REDIRECT_STDERR_TO_STDOUT=
# Default: 10240, i.e. maximum of 10MB in total can be extracted.
MAX_EXTRACT_SIZE=

# Maximum number of submissions that can be created with batch create.
# Maximum number of submissions that can be created or get in a batch.
# Default: 20
MAX_SUBMISSION_BATCH_SIZE=

0 comments on commit cb676d6

Please sign in to comment.