diff --git a/app/controllers/concerns/file_parameters.rb b/app/controllers/concerns/file_parameters.rb index 8298dabc..85675ce7 100644 --- a/app/controllers/concerns/file_parameters.rb +++ b/app/controllers/concerns/file_parameters.rb @@ -5,7 +5,8 @@ module FileParameters if exercise && params # We only want to load the files once, to avoid multiple database queries. # Further, we use `unscope` to avoid that the `order` scope is applied - files = CodeOcean::File.unscope(:order).where(id: params.values.pluck(:file_id)) + # Optimization: We query for the `file_type` here, which is used in `CodeOcean::File#set_ancestor_values`. + files = CodeOcean::File.unscope(:order).where(id: params.values.pluck(:file_id)).includes(:file_type) params.reject do |_, file_attributes| # This mechanism seems cumbersome, but we cannot use an index here. @@ -19,6 +20,10 @@ module FileParameters next true if file.context_type == 'Submission' && (file.context.user_id != current_user.id || file.context.user_type != current_user.class.name) next true if file.context_type == 'CommunitySolution' && controller_name != 'community_solutions' + # Optimization: We already queried the ancestor file, let's reuse the object. + file_attributes[:file] = file + file_attributes.delete(:file_id) + false end else diff --git a/app/controllers/remote_evaluation_controller.rb b/app/controllers/remote_evaluation_controller.rb index d89a6bfa..63aecf23 100644 --- a/app/controllers/remote_evaluation_controller.rb +++ b/app/controllers/remote_evaluation_controller.rb @@ -86,11 +86,10 @@ class RemoteEvaluationController < ApplicationController files_attributes = remote_evaluation_params[:files_attributes] submission_params = remote_evaluation_params.except(:validation_token) - submission_params[:exercise_id] = remote_evaluation_mapping.exercise_id - submission_params[:user_id] = remote_evaluation_mapping.user_id + submission_params[:exercise] = remote_evaluation_mapping.exercise + submission_params[:user] = remote_evaluation_mapping.user submission_params[:study_group_id] = remote_evaluation_mapping.study_group_id submission_params[:cause] = cause - submission_params[:user_type] = remote_evaluation_mapping.user_type submission_params[:files_attributes] = reject_illegal_file_attributes(remote_evaluation_mapping.exercise, files_attributes) submission_params diff --git a/app/models/code_ocean/file.rb b/app/models/code_ocean/file.rb index 9af290d0..20e7bacf 100644 --- a/app/models/code_ocean/file.rb +++ b/app/models/code_ocean/file.rb @@ -131,7 +131,7 @@ module CodeOcean end def set_ancestor_values - %i[feedback_message file_type_id hidden name path read_only role weight].each do |attribute| + %i[feedback_message file_type hidden name path read_only role weight].each do |attribute| send(:"#{attribute}=", ancestor.send(attribute)) end end