From 13b0d45e255ff44834407b00e77f7ffac0057ae0 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 13 Nov 2020 14:38:24 +0500 Subject: [PATCH] Check for 4 sessions only in inexpired ones --- app/models/epp_session.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/epp_session.rb b/app/models/epp_session.rb index 6bec39ee3..a6fb97ed2 100644 --- a/app/models/epp_session.rb +++ b/app/models/epp_session.rb @@ -11,13 +11,21 @@ class EppSession < ApplicationRecord alias_attribute :last_access, :updated_at + scope :not_expired, + lambda { + where(':now <= (updated_at + interval :interval)', now: Time.zone.now, interval: interval) + } + def self.limit_reached?(registrar) - count = where(user_id: registrar.api_users.ids).count + count = where(user_id: registrar.api_users.ids).not_expired.count count >= sessions_per_registrar end + def self.interval + "#{timeout.parts.first.second} #{timeout.parts.first.first}" + end + def self.expired - interval = "#{timeout.parts.first.second} #{timeout.parts.first.first}" where(':now > (updated_at + interval :interval)', now: Time.zone.now, interval: interval) end