Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
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: 2 additions & 0 deletions app/jobs/scheduled/delete_old_chat_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def delete_public_channel_messages

ChatMessage
.in_public_channel
.with_deleted
.created_before(SiteSetting.chat_channel_retention_days.days.ago)
.in_batches(of: 200)
.each do |relation|
Expand All @@ -27,6 +28,7 @@ def delete_dm_channel_messages

ChatMessage
.in_dm_channel
.with_deleted
.created_before(SiteSetting.chat_dm_retention_days.days.ago)
.in_batches(of: 200)
.each do |relation|
Expand Down
30 changes: 30 additions & 0 deletions spec/jobs/delete_old_chat_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
created_at: base_date - 30.days - 1.second,
)
end
fab!(:public_trashed_days_old_30) do
Fabricate(
:chat_message,
chat_channel: public_channel,
message: "hi",
created_at: base_date - 30.days - 1.second,
)
end

fab!(:dm_channel) do
Fabricate(
Expand Down Expand Up @@ -67,6 +75,14 @@
created_at: base_date - 30.days - 1.second,
)
end
fab!(:dm_trashed_days_old_30) do
Fabricate(
:chat_message,
chat_channel: dm_channel,
message: "hi",
created_at: base_date - 30.days - 1.second,
)
end

before { freeze_time(base_date) }

Expand All @@ -87,6 +103,13 @@
expect { public_days_old_30 }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "deletes trashed messages correctly" do
SiteSetting.chat_channel_retention_days = 20
public_trashed_days_old_30.trash!
described_class.new.execute
expect { public_trashed_days_old_30.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "does nothing when no messages fall in the time range" do
SiteSetting.chat_channel_retention_days = 800
expect { described_class.new.execute }.to change { ChatMessage.in_public_channel.count }.by(0)
Expand Down Expand Up @@ -119,6 +142,13 @@
expect { dm_days_old_30 }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "deletes trashed messages correctly" do
SiteSetting.chat_dm_retention_days = 20
dm_trashed_days_old_30.trash!
described_class.new.execute
expect { dm_trashed_days_old_30.reload }.to raise_exception(ActiveRecord::RecordNotFound)
end

it "does nothing when no messages fall in the time range" do
SiteSetting.chat_dm_retention_days = 800
expect { described_class.new.execute }.to change { ChatMessage.in_dm_channel.count }.by(0)
Expand Down