diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index bb093bdcf..5d82fa40a 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -98,4 +98,22 @@ class RecentView < ApplicationModel return if !record.respond_to?(:permission) record.permission( current_user: user ) end + +=begin + +cleanup old entries + + RecentView.cleanup + +optional you can parse the max oldest entries + + RecentView.cleanup(1.month) + +=end + + def self.cleanup(diff = 1.month) + RecentView.where('created_at < ?', Time.zone.now - diff).delete_all + true + end + end diff --git a/db/migrate/20150701000002_add_cleanup2.rb b/db/migrate/20150701000002_add_cleanup2.rb new file mode 100644 index 000000000..010324e5c --- /dev/null +++ b/db/migrate/20150701000002_add_cleanup2.rb @@ -0,0 +1,15 @@ +class AddCleanup2 < ActiveRecord::Migration + def up + + # delete old entries + Scheduler.create_or_update( + name: 'Delete old entries.', + method: 'RecentView.cleanup', + period: 1.day, + prio: 2, + active: true, + updated_by_id: 1, + created_by_id: 1, + ) + end +end