forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurging.rb
48 lines (39 loc) · 1.14 KB
/
purging.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module MiqReportResult::Purging
extend ActiveSupport::Concern
include PurgingMixin
module ClassMethods
def purge_mode_and_value
value = ::Settings.reporting.history.keep_reports
mode = value.number_with_method? ? :date : :remaining
value = value.to_i_with_method.seconds.ago.utc if mode == :date
return mode, value
end
def purge_window_size
::Settings.reporting.history.purge_window_size
end
def purge_count(mode, value)
send("purge_count_by_#{mode}", value)
end
def purge(mode, value, window = nil, &block)
send("purge_by_#{mode}", value, window, &block)
end
def purge_associated_records(ids)
MiqReportResultDetail.where(:miq_report_result_id => ids).delete_all
BinaryBlob.where(:resource_type => name, :resource_id => ids).destroy_all
end
private
#
# By Remaining
#
# @return [Symbol, Array<Symbol>] resource that is referenced by this table.
def purge_remaining_foreign_key
:miq_report_id
end
#
# By Date
#
def purge_scope(older_than)
where(arel_table[:created_on].lt(older_than))
end
end
end