Improve performance of the FlowrController
This commit is contained in:
@ -5,7 +5,8 @@ class FlowrController < ApplicationController
|
|||||||
require_user!
|
require_user!
|
||||||
# get the latest submission for this user that also has a test run (i.e. structured_errors if applicable)
|
# get the latest submission for this user that also has a test run (i.e. structured_errors if applicable)
|
||||||
submission = Submission.joins(:testruns)
|
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
|
.merge(Testrun.order(created_at: :desc)).first
|
||||||
|
|
||||||
# Return if no submission was found
|
# 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
|
# verify authorization for the submission, as all queried errors are generated by this submission anyway
|
||||||
# and structured_errors don't have a policy yet
|
# and structured_errors don't have a policy yet
|
||||||
authorize(submission)
|
authorize(submission)
|
||||||
errors = StructuredError.where(submission_id: submission.id)
|
|
||||||
|
|
||||||
# for each error get all attributes, filter out uninteresting ones, and build a query
|
# 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|
|
attributes = error.structured_error_attributes.select do |attribute|
|
||||||
interesting?(attribute) and attribute.match
|
interesting?(attribute) and attribute.match
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user