1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/services/statistics/cleaner_service.rb

31 lines
941 B
Ruby
Raw Normal View History

2022-08-29 17:34:09 +02:00
# frozen_string_literal: true
# Clean the existing statistics
class Statistics::CleanerService
include Statistics::Concerns::HelpersConcern
class << self
def clean_stat(options = default_options)
client = Elasticsearch::Model.client
2022-10-11 17:23:45 +02:00
%w[Account Event Machine Project Subscription Training User Space Order].each do |o|
2022-08-29 17:34:09 +02:00
model = "Stats::#{o}".constantize
2023-02-01 17:56:14 +01:00
dates = (to_date(options[:start_date]).to_date..to_date(options[:end_date]).to_date).to_a
# elasticsearch does not support more than 1024 query arguments
dates.each_slice(1024) do |slice_dates|
client.delete_by_query(
index: model.index_name,
type: model.document_type,
body: {
query: {
terms: {
date: slice_dates.map { |d| format_date(d) }
}
}
}
2023-02-01 17:56:14 +01:00
)
end
2022-08-29 17:34:09 +02:00
end
end
end
end