Skip to content
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

Remove duplicate metric_rollups not dealing with active relation #16166

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameswnl I just noticed this looking at the diff in git, can you remove the tailing whitespace here? It was added in 9dab1c4

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