diff --git a/app/controllers/flowr_controller.rb b/app/controllers/flowr_controller.rb index e2c0e056..278fa31b 100644 --- a/app/controllers/flowr_controller.rb +++ b/app/controllers/flowr_controller.rb @@ -5,7 +5,8 @@ class FlowrController < ApplicationController require_user! # get the latest submission for this user that also has a test run (i.e. structured_errors if applicable) submission = Submission.joins(:testruns) - .where(submissions: {user_id: current_user.id, user_type: current_user.class.name}) + .where(submissions: {user: current_user}) + .includes(structured_errors: [structured_error_attributes: [:error_template_attribute]]) .merge(Testrun.order(created_at: :desc)).first # Return if no submission was found @@ -18,10 +19,9 @@ class FlowrController < ApplicationController # verify authorization for the submission, as all queried errors are generated by this submission anyway # and structured_errors don't have a policy yet authorize(submission) - errors = StructuredError.where(submission_id: submission.id) # for each error get all attributes, filter out uninteresting ones, and build a query - insights = errors.map do |error| + insights = submission.structured_errors.map do |error| attributes = error.structured_error_attributes.select do |attribute| interesting?(attribute) and attribute.match end