diff options
| author | mo <mo.khan@gmail.com> | 2017-09-24 12:56:20 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2017-09-24 12:56:20 -0600 |
| commit | a67e0cb103f76df6095257857e5f980340f3c940 (patch) | |
| tree | 7602d8e3f1c2bb721afaf4d891c1e3800c7166c6 /app/models | |
| parent | 96d66bcdb7bad43c3ec08349d2d978aec307ec90 (diff) | |
upgrade to rails 5.1
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/photo.rb | 2 | ||||
| -rw-r--r-- | app/models/user_session.rb | 15 | ||||
| -rw-r--r-- | app/models/version.rb | 5 |
3 files changed, 17 insertions, 5 deletions
diff --git a/app/models/photo.rb b/app/models/photo.rb index 2c9127e4..a3f3e547 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -1,5 +1,5 @@ class Photo < ApplicationRecord - belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true + belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true, optional: true scope :processed, ->{ where(image_processing: nil) } def url_for(version_key, asset_host = ENV['ASSET_HOST']) diff --git a/app/models/user_session.rb b/app/models/user_session.rb index 3456c7d0..9dae0857 100644 --- a/app/models/user_session.rb +++ b/app/models/user_session.rb @@ -4,15 +4,20 @@ class UserSession < ApplicationRecord has_one :location, as: :locatable before_create :set_unique_key attr_readonly :key - scope :active, -> { where("accessed_at >= ?", 2.weeks.ago).where(revoked_at: nil).includes(:user) } + scope :active, -> do + where("accessed_at >= ?", 20.minutes.ago) + .where("created_at >= ?", 1.day.ago) + .where(revoked_at: nil) + .includes(:user) + end def revoke! - self.revoked_at = Time.now + self.revoked_at = Time.current save! end def access(request) - self.accessed_at = Time.now + self.accessed_at = Time.current self.ip = request.ip self.user_agent = request.user_agent self.location = Location.build_from_ip(request.ip) @@ -28,6 +33,10 @@ class UserSession < ApplicationRecord return nil if key.blank? self.active.find_by(key: key) end + + def sweep(time = 1.day) + delete_all("accessed_at < ?", time.ago) + end end private diff --git a/app/models/version.rb b/app/models/version.rb index 43ab3ef0..f15676a4 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -19,7 +19,10 @@ class Version if photo.is_processed? "#{asset_host}/#{blob_key}" else - ActionController::Base.helpers.asset_path("#{key}_default.png") + ActionController::Base.helpers.asset_path( + "#{key}_default.png", + skip_pipeline: true + ) end end |
