Add GeoLiteCity, and stats pruning code

This commit is contained in:
Kyle Drake 2015-04-30 12:43:21 -07:00
parent 6a8fa080eb
commit 9c80d5eecd
5 changed files with 33 additions and 5 deletions

View file

@ -1,5 +1,6 @@
class Stat < Sequel::Model
GEOCITY_PATH = './files/GeoLiteCity.dat'
FREE_RETAINMENT_DAYS = 7
many_to_one :site
one_to_many :stat_referrers
@ -7,6 +8,13 @@ class Stat < Sequel::Model
one_to_many :stat_paths
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
].first
end
def parse_logfiles(path)
Dir["#{path}/*.log"].each do |log_path|
site_logs = {}