mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-30 06:31:16 +00:00
Delete sessions older than two weeks
This affects users that are actively purchasing, so 2 weeks data is more than enough. Others can afford to log in again.
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TruncateData
|
||||
# This model lets us operate on the sessions DB table using ActiveRecord's
|
||||
# methods within the scope of this service. This relies on the AR's
|
||||
# convention where a Session model maps to a sessions table.
|
||||
class Session < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def initialize(months_to_keep = nil)
|
||||
@date = (months_to_keep || 3).months.ago
|
||||
end
|
||||
@@ -36,7 +42,7 @@ class TruncateData
|
||||
Spree::ReturnAuthorization.delete_all
|
||||
Spree::StateChange.delete_all("created_at < '#{1.month.ago.to_date}'")
|
||||
Spree::LogEntry.delete_all("created_at < '#{1.month.ago.to_date}'")
|
||||
sql_delete_from "sessions"
|
||||
Session.delete_all("created_at < '#{2.weeks.ago.to_date}'")
|
||||
end
|
||||
|
||||
def truncate_subscriptions
|
||||
|
||||
@@ -7,6 +7,7 @@ describe TruncateData do
|
||||
allow(Spree::ReturnAuthorization).to receive(:delete_all)
|
||||
allow(Spree::StateChange).to receive(:delete_all)
|
||||
allow(Spree::LogEntry).to receive(:delete_all)
|
||||
allow(TruncateData::Session).to receive(:delete_all)
|
||||
end
|
||||
|
||||
context 'when months_to_keep is not specified' do
|
||||
@@ -36,6 +37,14 @@ describe TruncateData do
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{1.month.ago.to_date}'")
|
||||
end
|
||||
|
||||
it 'deletes sessions older than two weeks' do
|
||||
TruncateData.new.call
|
||||
|
||||
expect(TruncateData::Session)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{2.weeks.ago.to_date}'")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when months_to_keep is nil' do
|
||||
@@ -65,6 +74,14 @@ describe TruncateData do
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{1.month.ago.to_date}'")
|
||||
end
|
||||
|
||||
it 'deletes sessions older than two weeks' do
|
||||
TruncateData.new.call
|
||||
|
||||
expect(TruncateData::Session)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{2.weeks.ago.to_date}'")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when months_to_keep is specified' do
|
||||
@@ -98,6 +115,14 @@ describe TruncateData do
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{1.month.ago.to_date}'")
|
||||
end
|
||||
|
||||
it 'deletes sessions older than two weeks' do
|
||||
TruncateData.new.call
|
||||
|
||||
expect(TruncateData::Session)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{2.weeks.ago.to_date}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user