Skip to content

Commit

Permalink
Avoid .required? function in loops
Browse files Browse the repository at this point in the history
The check's required function actually checks the checkable
of the status_report, which is rather expensive

  SELECT  `status_reports`.* FROM `status_reports` WHERE `status_reports`.`id` = 32 LIMIT 1  [["id", 32], ["LIMIT", 1]]
  SELECT  `repositories`.* FROM `repositories` WHERE `repositories`.`id` = 342446 LIMIT 1  [["id", 342446], ["LIMIT", 1]]

And this is done for every check in the report. While we already know
the checkable (the repository), so just pass it to the partial.
  • Loading branch information
coolo committed Dec 17, 2018
1 parent 9559d3d commit 8c89c9a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/api/app/controllers/status/checks_controller.rb
Expand Up @@ -20,6 +20,7 @@ def update

if @check.save
@event_class.create(check_notify_params)
@checkable = @status_report.checkable
render :show
else
render_error(status: 422, errorcode: 'invalid_check', message: "Could not save check: #{@check.errors.full_messages.to_sentence}")
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/status/checks/_check.xml.builder
@@ -1,4 +1,4 @@
builder.check(name: object.name, required: object.required?) do |check|
builder.check(name: object.name, required: checkable.required_checks.include?(object.name)) do |check|
check.state object.state
check.short_description object.short_description
check.url object.url
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/status/checks/show.xml.builder
@@ -1 +1 @@
render(partial: 'check', locals: { builder: xml, object: @check })
render(partial: 'check', locals: { builder: xml, object: @check, checkable: @checkable })
3 changes: 2 additions & 1 deletion src/api/app/views/status/reports/show.xml.builder
@@ -1,6 +1,7 @@
xml.status_report(uuid: @status_report.uuid) do |xml|
@checks.each do |check|
render(partial: 'status/checks/check', locals: { builder: xml, object: check })
render(partial: 'status/checks/check', locals: { builder: xml, object: check,
checkable: @status_report.checkable })
end

@missing_checks.each do |name|
Expand Down

0 comments on commit 8c89c9a

Please sign in to comment.