-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add save hooks on MiqReportResult to remove groupings #17598
Add save hooks on MiqReportResult to remove groupings #17598
Conversation
app/models/miq_report_result.rb
Outdated
@@ -35,6 +35,9 @@ class MiqReportResult < ApplicationRecord | |||
end | |||
end | |||
|
|||
before_save { @_extra_groupings = report.extras.delete(:grouping) } | |||
after_commit { report.extras[:grouping] = @_extra_groupings } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting: This has to be an after_commit
instead of a after_save
, otherwise it puts the ActiveRecord
object into a dirty state, and causes an infinite loop. If this gets changed to the latter, the test should catch it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this witchcraft... So, are we removing it before we commit it to the DB but put it back into the in-memory object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we clear @_extra_groupings
after?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, are we removing it before we commit it to the DB but put it back into the in-memory object?
Yup, basically. Trying to play it safe just incase I missed something where this is used after it is saved.
Should we clear @_extra_groupings after?
I had that in there previously, but nothing is using that var, so I am tempted to just not bother. We aren't .dup
ing it, so just passing a reference of it around. Up to you though if you feel strongly one way or the other.
quite |
9f21198
to
071fd83
Compare
@jrafanie quiet you... |
Test failures are from this PR. Getting them fixed. |
4cd1f28
to
af169b6
Compare
app/models/miq_report_result.rb
Outdated
@@ -35,6 +35,9 @@ class MiqReportResult < ApplicationRecord | |||
end | |||
end | |||
|
|||
before_save { @_extra_groupings = report.extras.delete(:grouping) if report.kind_of?(MiqReport) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this needs a short comment about why we're doing this and a link to the BZ.
@@ -105,6 +105,23 @@ | |||
expect(report_result.report_results.table.data).not_to be_nil | |||
end | |||
|
|||
it "should not include `extras[:grouing]` in the report column" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: grouping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Butts... will fix
LGTM with the minor nitpicks I suggested. |
af169b6
to
e534eb2
Compare
@miq-bot add_label blocker |
@NickLaMuro if this can be backported, please add the label gaprindashvili/yes |
app/models/miq_report_result.rb
Outdated
@@ -35,6 +35,17 @@ class MiqReportResult < ApplicationRecord | |||
end | |||
end | |||
|
|||
# These two hooks of a fix for the following BZ: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this: These two hooks prevent temporary chargeback aggregation data to be retained in each miq_report_results row found in the following BZ:
app/models/miq_report_result.rb
Outdated
# | ||
# https://bugzilla.redhat.com/show_bug.cgi?id=1590908 | ||
# | ||
# The remove extra data that is not necessary to be saved to the DB, but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is The remove
a typo? Is it supposed to be These remove
app/models/miq_report_result.rb
Outdated
# https://bugzilla.redhat.com/show_bug.cgi?id=1590908 | ||
# | ||
# The remove extra data that is not necessary to be saved to the DB, but | ||
# allow it to be retained for the remainder of the instanation incase the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instantiation
in case
app/models/miq_report_result.rb
Outdated
# The remove extra data that is not necessary to be saved to the DB, but | ||
# allow it to be retained for the remainder of the instanation incase the | ||
# data is used to finish building the report results (the `after_commit` hook | ||
# specifically, most likely this is overkill. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the after_commit
hook specifically, is probably overkill but allows us to not break existing code that expects the temporary chargeback data in the instantiated object
^ Maybe?
0bfcd41
to
0addd38
Compare
https://bugzilla.redhat.com/show_bug.cgi?id=1590908 The `report.extras[:groupings]` on MiqReportResult were being serialized to the `report` column, and on certain chargeback reports, can get quite large. This data is not needed, so we remove it prior to saving. The `after_commit` exists in case there is a use for the saved data after it has been saved and still used within the original instance of the MiqReportResult for building the result. Most likely this is overkill, but for now it is in place as a safety measure. Also, `after_commit` is used because a `after_save` will cause an "stack level too deep" error since editing the report value causes the record to be put into a `dirty` state, and the ActiveRecord internals don't like that.
0addd38
to
253cf7a
Compare
Wow, bot is harsh |
Checked commit NickLaMuro@253cf7a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@miq-bot add_label reporting, enhancement, gaprindashvili/yes |
@miq-bot add_label fine/yes |
…g_saved_on_report_results Add save hooks on MiqReportResult to remove groupings (cherry picked from commit 28dc337) https://bugzilla.redhat.com/show_bug.cgi?id=1594387
Fine backport details:
|
…g_saved_on_report_results Add save hooks on MiqReportResult to remove groupings (cherry picked from commit 28dc337) https://bugzilla.redhat.com/show_bug.cgi?id=1594386
Gaprindashvili backport details:
|
The
report.extras[:groupings]
on MiqReportResult were being serialized to thereport
column, and on certain chargeback reports, can get quite large. This data is not needed, so we remove it prior to saving.The after_commit exists in case there is a use for the saved data after it has been saved and still used within the original instance of the MiqReportResult for building the result. Most likely this is overkill, but for now it is in place as a safety measure.
Links