Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
RemoveEvents: Save less events
Browse files Browse the repository at this point in the history
We have went over the row limit again. This is probably fine to save
less data.
  • Loading branch information
tskogberg committed May 9, 2016
1 parent acdd1fc commit 0cc6d50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/tasks/remove_events.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
class RemoveEvents
method_object

LIMIT = 4.months.ago

def call
destroy_events_older_than_the_limit
end

private

def destroy_events_older_than_the_limit
limit = 5.months.ago
# We have no associated relations so we can use delete_all
number_of_events_deleted = Event.where("created_at < ?", limit).delete_all
number_of_events_deleted = Event.where("created_at < ?", LIMIT).delete_all
EventsData.instance.decrement!(:total_events, number_of_events_deleted)
puts "Deleted events older than #{limit}"
puts "Deleted events older than #{LIMIT}"
end
end
2 changes: 1 addition & 1 deletion spec/lib/tasks/remove_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe RemoveEvents, ".call" do
it "removes data older than the limit and updates total events" do
# No need for the logging output in the test
limit = 5.months.ago
limit = RemoveEvents::LIMIT
allow_any_instance_of(RemoveEvents).to receive(:puts)

event_older_than_the_limit = create_event_at(limit - 1.second)
Expand Down

0 comments on commit 0cc6d50

Please sign in to comment.