From b321ff55417c65b825861a2dafcbda26f615081f Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Thu, 14 Jun 2018 16:28:46 -0500 Subject: [PATCH] Add MiqReportResult#contains_records? https://bugzilla.redhat.com/show_bug.cgi?id=1590908 Like `MiqReportResult#has_report?`, this is a faster version of checking if the report_result has rows. Like `MiqReport#contains_records?`, this will check against the `extras` attribute on the deserialized version of the `report` column, but instead of using the `table` value (which is not saved into the `report` column), just do a light SQL existence check on the `html_details` to confirm there are generated rows for this report. The SQL query most likely won't be needed, and it is super light weight, only returning a single digit, or an empty result set if there are no records. --- app/models/miq_report_result.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/miq_report_result.rb b/app/models/miq_report_result.rb index 420af24963ed..23043ab36510 100644 --- a/app/models/miq_report_result.rb +++ b/app/models/miq_report_result.rb @@ -60,6 +60,13 @@ def valid_report_column? report.kind_of?(MiqReport) end + # Use this over `report_results.contains_records?` if you don't need to + # access the binary_blob associated with the MiqReportResult (chances are you + # don't need it) + def contains_records? + (report && (report.extras || {})[:total_html_rows].to_i > 0) || html_details.exists? + end + def report_results if binary_blob data = binary_blob.data