mirror of
https://github.com/neocities/neocities.git
synced 2025-06-27 14:44:35 +02:00
finish up pruning for stats
This commit is contained in:
parent
918231ea0f
commit
704011a1c0
6 changed files with 61 additions and 35 deletions
|
@ -1,11 +1,15 @@
|
|||
class StatPath < Sequel::Model
|
||||
RETAINMENT_PERIOD = 7.days
|
||||
RETAINMENT_DAYS = 7
|
||||
|
||||
many_to_one :site
|
||||
|
||||
def self.prune!
|
||||
where{created_at < (RETAINMENT_DAYS-2).days.ago.to_date}.delete
|
||||
end
|
||||
|
||||
def self.create_or_get(site_id, name)
|
||||
opts = {site_id: site_id, name: name}
|
||||
stat_path = where(opts).where{created_at > RETAINMENT_PERIOD.ago}.first
|
||||
stat_path = where(opts).where{created_at > RETAINMENT_DAYS.days.ago}.first
|
||||
DB[table_name].lock('EXCLUSIVE') {
|
||||
stat_path = create opts.merge created_at: Date.today
|
||||
} if stat_path.nil?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue