Reduce SQL queries for external user statistics
Fixes CODEOCEAN-100 Fixes CODEOCEAN-YN Fixes CODEOCEAN-10H
This commit is contained in:
@ -521,7 +521,8 @@ class ExercisesController < ApplicationController
|
||||
submissions = Submission.where(contributor: @external_user, exercise: @exercise)
|
||||
.in_study_group_of(current_user)
|
||||
.order(:created_at)
|
||||
@show_autosaves = params[:show_autosaves] == 'true' || submissions.none? {|s| s.cause != 'autosave' }
|
||||
.includes(:exercise, testruns: [:testrun_messages, {file: [:file_type]}], files: [:file_type])
|
||||
@show_autosaves = params[:show_autosaves] == 'true' || submissions.where.not(cause: 'autosave').none?
|
||||
submissions = submissions.where.not(cause: 'autosave') unless @show_autosaves
|
||||
interventions = UserExerciseIntervention.where('user_id = ? AND exercise_id = ?', @external_user.id,
|
||||
@exercise.id)
|
||||
|
@ -7,6 +7,8 @@ class Testrun < ApplicationRecord
|
||||
belongs_to :testrun_execution_environment, optional: true, dependent: :destroy
|
||||
has_many :testrun_messages, dependent: :destroy
|
||||
|
||||
CONSOLE_OUTPUT = %i[stdout stderr].freeze
|
||||
|
||||
enum status: {
|
||||
ok: 0,
|
||||
failed: 1,
|
||||
@ -21,6 +23,10 @@ class Testrun < ApplicationRecord
|
||||
validates :status, presence: true
|
||||
|
||||
def log
|
||||
if testrun_messages.loaded?
|
||||
testrun_messages.filter {|m| m.cmd_write? && CONSOLE_OUTPUT.include?(m.stream) }.pluck(:log).join.presence
|
||||
else
|
||||
testrun_messages.output.pluck(:log).join.presence
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -76,7 +76,7 @@ h1
|
||||
td = this.cause
|
||||
td = this.score
|
||||
td.align-middle
|
||||
-this.testruns.includes(:file).order("files.name").each do |run|
|
||||
-this.testruns.sort_by {|t| [t.file&.name ? 0 : 1, t.file&.name]}.each do |run|
|
||||
- if run.passed
|
||||
.unit-test-result.positive-result title=[run.file&.filepath, run.log].join.strip
|
||||
- else
|
||||
|
Reference in New Issue
Block a user