Skip to content

Commit

Permalink
Merge pull request #16166 from jameswnl/dedup
Browse files Browse the repository at this point in the history
Remove duplicate metric_rollups not dealing with active relation
(cherry picked from commit 15e48b8)

https://bugzilla.redhat.com/show_bug.cgi?id=1505415
  • Loading branch information
agrare authored and simaishi committed Nov 13, 2017
1 parent caf0a33 commit 5702efb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/metric/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def self.sanitize_start_end_time(interval, interval_name, start_time, end_time)

def self.remove_duplicate_timestamps(recs)
if recs.respond_to?(:klass) # active record relation
return recs unless recs.klass.kind_of?(Metric) || recs.klass.kind_of?(MetricRollup)
return recs unless recs.klass <= Metric || recs.klass <= MetricRollup
elsif recs.empty? || !recs.all? { |r| r.kind_of?(Metric) || r.kind_of?(MetricRollup) }
return recs
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/metric/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
expect(recs).to match_array([metric_rollup_1, metric_rollup_3])
end

it "dedups a given scope" do
recs = described_class.remove_duplicate_timestamps(MetricRollup.where(:id => [metric_rollup_1, metric_rollup_2, metric_rollup_3]))
expect(recs).to match_array([metric_rollup_1, metric_rollup_3])
end

it "returns only unique records and merge values with the same timestamp" do
metric_rollup_1.cpu_usage_rate_average = nil
metric_rollup_1.save
Expand Down

0 comments on commit 5702efb

Please sign in to comment.