Skip to content

Commit

Permalink
Add MiqReportResult#contains_records?
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickLaMuro committed Jun 14, 2018
1 parent 0dbaf68 commit e567768
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/miq_report_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def has_report?
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
Expand Down

0 comments on commit e567768

Please sign in to comment.