diff options
author | ysksn <bluewhale1982@gmail.com> | 2019-02-03 03:11:38 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-02-02 19:11:38 +0100 |
commit | bcfff65195f557dc086470f91b4c90b15c004cf7 (patch) | |
tree | cdf805998758278b41cd8ab0cc8dd864d8047c57 /app/models | |
parent | 6a5e3da6b044e50635d293c2716883cc5627e4c8 (diff) |
Create Redisable#redis (#9633)
* Create Redisable * Use #redis instead of Redis.current
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/redisable.rb | 11 | ||||
-rw-r--r-- | app/models/feed.rb | 6 | ||||
-rw-r--r-- | app/models/trending_tags.rb | 6 |
3 files changed, 15 insertions, 8 deletions
diff --git a/app/models/concerns/redisable.rb b/app/models/concerns/redisable.rb new file mode 100644 index 000000000..c6cf97359 --- /dev/null +++ b/app/models/concerns/redisable.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Redisable + extend ActiveSupport::Concern + + private + + def redis + Redis.current + end +end diff --git a/app/models/feed.rb b/app/models/feed.rb index 5bce88f25..0e8943ff8 100644 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Feed + include Redisable + def initialize(type, id) @type = type @id = id @@ -27,8 +29,4 @@ class Feed def key FeedManager.instance.key(@type, @id) end - - def redis - Redis.current - end end diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index 3a8be2164..148535c21 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -7,6 +7,8 @@ class TrendingTags THRESHOLD = 5 class << self + include Redisable + def record_use!(tag, account, at_time = Time.now.utc) return if disallowed_hashtags.include?(tag.name) || account.silenced? || account.bot? @@ -59,9 +61,5 @@ class TrendingTags @disallowed_hashtags = @disallowed_hashtags.split(' ') if @disallowed_hashtags.is_a? String @disallowed_hashtags = @disallowed_hashtags.map(&:downcase) end - - def redis - Redis.current - end end end |