Skip to content

Commit

Permalink
Add MiqReportResult#contains_records?
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickLaMuro committed Jun 18, 2018
1 parent 6b2e57d commit b8293ff
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 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].positive?) || html_details.exists?
end

def report_results
if binary_blob
data = binary_blob.data
Expand Down

0 comments on commit b8293ff

Please sign in to comment.