From 3057eda4b0a221be58a27d73a9bf7ad601612228 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Thu, 30 Apr 2020 00:44:00 -0700 Subject: [PATCH] ensure stats for supporter children are retained --- models/site.rb | 6 ++++++ models/stat.rb | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/models/site.rb b/models/site.rb index 81ff108c..d4232d72 100644 --- a/models/site.rb +++ b/models/site.rb @@ -200,6 +200,12 @@ class Site < Sequel::Model one_to_many :archives + def self.supporter_ids + parent_supporters = DB[%{SELECT id FROM sites WHERE plan_type IS NOT NULL AND plan_type != 'free'}].all.collect {|s| s[:id]} + child_supporters = DB[%{select a.id as id from sites a, sites b where a.parent_site_id is not null and a.parent_site_id=b.id and (a.plan_type != 'free' or b.plan_type != 'free')}].all.collect {|s| s[:id]} + parent_supporters + child_supporters + end + def self.newsletter_sites Site.select(:email). exclude(email: 'nil').exclude(is_banned: true). diff --git a/models/stat.rb b/models/stat.rb index 83e85f9f..c50cab97 100644 --- a/models/stat.rb +++ b/models/stat.rb @@ -12,8 +12,9 @@ class Stat < Sequel::Model class << self def prune! DB[ - "DELETE FROM stats WHERE created_at < ? AND site_id NOT IN (SELECT id FROM sites WHERE plan_type IS NOT NULL OR plan_type != 'free')", - (FREE_RETAINMENT_DAYS-1).days.ago.to_date.to_s + "DELETE FROM stats WHERE created_at < ? AND site_id NOT IN ?", + (FREE_RETAINMENT_DAYS-1).days.ago.to_date.to_s, + Site.supporter_ids ].first end