Improve performance of the FlowrController

This commit is contained in:
Sebastian Serth
2023-03-20 23:52:55 +01:00
parent 09809cc12e
commit 7af7484f7a

View File

@ -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