neocities/models/stat_path.rb
2015-05-02 02:34:24 -07:00

15 lines
387 B
Ruby

class StatPath < Sequel::Model
RETAINMENT_PERIOD = 7.days
many_to_one :site
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
DB[table_name].lock('EXCLUSIVE') {
stat_path = create opts.merge created_at: Date.today
} if stat_path.nil?
stat_path
end
end