mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Update data retention periods
Sessions and cart data are removed if older than 3 months, instead of 6.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RemoveTransientData
|
||||
RETENTION_PERIOD = 6.months.ago.to_date
|
||||
MEDIUM_RETENTION = 6.months.ago.to_date
|
||||
SHORT_RETENTION = 3.months.ago.to_date
|
||||
|
||||
# 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
|
||||
@@ -12,9 +13,9 @@ class RemoveTransientData
|
||||
def call
|
||||
Rails.logger.info("#{self.class.name}: processing")
|
||||
|
||||
Spree::StateChange.where("created_at < ?", RETENTION_PERIOD).delete_all
|
||||
Spree::LogEntry.where("created_at < ?", RETENTION_PERIOD).delete_all
|
||||
Session.where("updated_at < ?", RETENTION_PERIOD).delete_all
|
||||
Spree::StateChange.where("created_at < ?", MEDIUM_RETENTION).delete_all
|
||||
Spree::LogEntry.where("created_at < ?", MEDIUM_RETENTION).delete_all
|
||||
Session.where("updated_at < ?", SHORT_RETENTION).delete_all
|
||||
|
||||
clear_old_cart_data!
|
||||
clear_line_item_option_values!
|
||||
@@ -23,7 +24,7 @@ class RemoveTransientData
|
||||
private
|
||||
|
||||
def clear_old_cart_data!
|
||||
old_carts = Spree::Order.where("state = 'cart' AND updated_at < ?", RETENTION_PERIOD)
|
||||
old_carts = Spree::Order.where("state = 'cart' AND updated_at < ?", SHORT_RETENTION)
|
||||
old_cart_line_items = Spree::LineItem.where(order_id: old_carts)
|
||||
old_cart_adjustments = Spree::Adjustment.where(order_id: old_carts)
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ require 'tasks/data/remove_transient_data'
|
||||
|
||||
describe RemoveTransientData do
|
||||
describe '#call' do
|
||||
let(:retention_period) { RemoveTransientData::RETENTION_PERIOD }
|
||||
let(:medium_retention) { RemoveTransientData::MEDIUM_RETENTION }
|
||||
let(:short_retention) { RemoveTransientData::SHORT_RETENTION }
|
||||
|
||||
before do
|
||||
allow(Spree::StateChange).to receive(:delete_all)
|
||||
@@ -15,21 +16,21 @@ describe RemoveTransientData do
|
||||
end
|
||||
|
||||
it 'deletes state changes older than rentention_period' do
|
||||
Spree::StateChange.create(created_at: retention_period - 1.day)
|
||||
Spree::StateChange.create(created_at: medium_retention - 1.day)
|
||||
|
||||
RemoveTransientData.new.call
|
||||
expect(Spree::StateChange.all).to be_empty
|
||||
end
|
||||
|
||||
it 'deletes log entries older than retention_period' do
|
||||
Spree::LogEntry.create(created_at: retention_period - 1.day)
|
||||
Spree::LogEntry.create(created_at: medium_retention - 1.day)
|
||||
|
||||
expect { RemoveTransientData.new.call }
|
||||
.to change(Spree::LogEntry, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'deletes sessions older than retention_period' do
|
||||
RemoveTransientData::Session.create(session_id: 1, updated_at: retention_period - 1.day)
|
||||
RemoveTransientData::Session.create(session_id: 1, updated_at: short_retention - 1.day)
|
||||
|
||||
RemoveTransientData.new.call
|
||||
|
||||
@@ -44,7 +45,7 @@ describe RemoveTransientData do
|
||||
let!(:line_item) { create(:line_item, order: cart, variant: variant) }
|
||||
let!(:adjustment) { create(:adjustment, order: cart) }
|
||||
|
||||
let!(:old_cart) { create(:order, state: 'cart', updated_at: retention_period - 1.day) }
|
||||
let!(:old_cart) { create(:order, state: 'cart', updated_at: short_retention - 1.day) }
|
||||
let!(:old_line_item) { create(:line_item, order: old_cart, variant: variant) }
|
||||
let!(:old_adjustment) { create(:adjustment, order: old_cart) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user