Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
Add a rake task to trim old sessions from db As we store the sessions on database, a good practice it is to remove old sessions so our table don't grow exponentially. We're removing all sessions untouched by more than 30 days.
config/schedule.rb | 4 ++++ lib/tasks/sessions.rake | 7 +++++++
diff --git a/config/schedule.rb b/config/schedule.rb index 7be5812873b2f5c162931fbc2b555273c5871d46..5682bbe86236956094ffd5b04d7fc8add2c01aee 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -25,6 +25,10 @@ every 1.day do runner "SearchTerm.calculate_scores" end +every 1.day do + rake "sessions:trim" +end + every 30.days do runner "ProfileSuggestion.generate_all_profile_suggestions" end diff --git a/lib/tasks/sessions.rake b/lib/tasks/sessions.rake new file mode 100644 index 0000000000000000000000000000000000000000..849119e2a70612ecf23b07bca70316b2bf0fc6d2 --- /dev/null +++ b/lib/tasks/sessions.rake @@ -0,0 +1,7 @@ +namespace :sessions do + desc "Trim old sessions from the table" + task :trim => [:environment, 'db:load_config'] do + Session.where("updated_at < ?", 30.days.ago).delete_all + end +end +