Skip to content

Commit 6c8dd6a

Browse files
committed
Clean up old activity data
1 parent d0c4c40 commit 6c8dd6a

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class DeleteExpiredActivityJob < ApplicationJob
2+
queue_as :deletion
3+
4+
def perform(*args)
5+
ContentActivity.expired.delete_all
6+
HashtagActivity.expired.delete_all
7+
LinkActivity.expired.delete_all
8+
end
9+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module ExpirableConcern
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
scope :expired, -> { where(hour_of_activity: ..((14.days + 1.hour).ago)) }
6+
end
7+
end

app/models/content_activity.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class ContentActivity < ApplicationRecord
2+
include ExpirableConcern
23
include ScorableConcern
34

45
belongs_to :content_object

app/models/hashtag_activity.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class HashtagActivity < ApplicationRecord
2+
include ExpirableConcern
23
include LanguageTaggableConcern
34
include ScorableConcern
45

app/models/link_activity.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class LinkActivity < ApplicationRecord
2+
include ExpirableConcern
23
include LanguageTaggableConcern
34
include ScorableConcern
45

config/recurring.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
# command: "SoftDeletedRecord.due.delete_all"
99
# priority: 2
1010
# schedule: at 5am every day
11+
production:
12+
delete_expired_activity:
13+
class: DeleteExpiredActivityJob
14+
schedule: every hour

0 commit comments

Comments
 (0)