ensure stats for supporter children are retained

This commit is contained in:
Kyle Drake 2020-04-30 00:44:00 -07:00
parent 10018c5124
commit 3057eda4b0
2 changed files with 9 additions and 2 deletions

View file

@ -200,6 +200,12 @@ class Site < Sequel::Model
one_to_many :archives 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 def self.newsletter_sites
Site.select(:email). Site.select(:email).
exclude(email: 'nil').exclude(is_banned: true). exclude(email: 'nil').exclude(is_banned: true).

View file

@ -12,8 +12,9 @@ class Stat < Sequel::Model
class << self class << self
def prune! def prune!
DB[ 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')", "DELETE FROM stats WHERE created_at < ? AND site_id NOT IN ?",
(FREE_RETAINMENT_DAYS-1).days.ago.to_date.to_s (FREE_RETAINMENT_DAYS-1).days.ago.to_date.to_s,
Site.supporter_ids
].first ].first
end end