EXPIRE_AFTER = 90.days.seconds
class << self
+ include Redisable
+
def increment(prefix)
key = [prefix, current_week].join(':')
private
- def redis
- Redis.current
- end
-
def current_week
Time.zone.today.cweek
end
class ActivityPub::Activity
include JsonLdHelper
+ include Redisable
def initialize(json, account, **options)
@json = json
@object_uri ||= value_or_id(@object)
end
- def redis
- Redis.current
- end
-
def distribute(status)
crawl_links(status)
class FeedManager
include Singleton
+ include Redisable
MAX_ITEMS = 400
def unpush_from_home(account, status)
return false unless remove_from_feed(:home, account.id, status)
- Redis.current.publish("timeline:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s))
+ redis.publish("timeline:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s))
true
end
def unpush_from_list(list, status)
return false unless remove_from_feed(:list, list.id, status)
- Redis.current.publish("timeline:list:#{list.id}", Oj.dump(event: :delete, payload: status.id.to_s))
+ redis.publish("timeline:list:#{list.id}", Oj.dump(event: :delete, payload: status.id.to_s))
true
end
private
- def redis
- Redis.current
- end
-
def push_update_required?(timeline_id)
redis.exists("subscribed:#{timeline_id}")
end
# frozen_string_literal: true
class OStatus::Activity::Base
+ include Redisable
+
def initialize(xml, account = nil, **options)
@xml = xml
@account = account
Status.find_by(uri: uri)
end
end
-
- def redis
- Redis.current
- end
end
}.freeze
class << self
+ include Redisable
+
def record(account_id, target_account_id, action)
return if account_id == target_account_id
return [] if account_ids.empty?
Account.searchable.where(id: account_ids)
end
-
- private
-
- def redis
- Redis.current
- end
end
end
--- /dev/null
+# frozen_string_literal: true
+
+module Redisable
+ extend ActiveSupport::Concern
+
+ private
+
+ def redis
+ Redis.current
+ end
+end
# frozen_string_literal: true
class Feed
+ include Redisable
+
def initialize(type, id)
@type = type
@id = id
def key
FeedManager.instance.key(@type, @id)
end
-
- def redis
- Redis.current
- end
end
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?
@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
class BatchedRemoveStatusService < BaseService
include StreamEntryRenderer
+ include Redisable
# Delete given statuses and reblogs of them
# Dispatch PuSH updates of the deleted statuses, but only local ones
end
end
- def redis
- Redis.current
- end
-
def build_xml(stream_entry)
return @activity_xml[stream_entry.id] if @activity_xml.key?(stream_entry.id)
# frozen_string_literal: true
class FollowService < BaseService
+ include Redisable
+
# Follow a remote user, notify remote user about the follow
# @param [Account] source_account From which to follow
# @param [String, Account] uri User URI to follow in the form of username@domain (or account record)
follow
end
- def redis
- Redis.current
- end
-
def build_follow_request_xml(follow_request)
OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.follow_request_salmon(follow_request))
end
# frozen_string_literal: true
class PostStatusService < BaseService
+ include Redisable
+
MIN_SCHEDULE_OFFSET = 5.minutes.freeze
# Post a text status update, fetch and notify remote users mentioned
ProcessHashtagsService.new
end
- def redis
- Redis.current
- end
-
def scheduled?
@scheduled_at.present?
end
class RemoveStatusService < BaseService
include StreamEntryRenderer
+ include Redisable
def call(status, **options)
@payload = Oj.dump(event: :delete, payload: status.id.to_s)
def remove_from_affected
@mentions.map(&:account).select(&:local?).each do |account|
- Redis.current.publish("timeline:#{account.id}", @payload)
+ redis.publish("timeline:#{account.id}", @payload)
end
end
return unless @status.public_visibility?
@tags.each do |hashtag|
- Redis.current.publish("timeline:hashtag:#{hashtag}", @payload)
- Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local?
+ redis.publish("timeline:hashtag:#{hashtag}", @payload)
+ redis.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local?
end
end
def remove_from_public
return unless @status.public_visibility?
- Redis.current.publish('timeline:public', @payload)
- Redis.current.publish('timeline:public:local', @payload) if @status.local?
+ redis.publish('timeline:public', @payload)
+ redis.publish('timeline:public:local', @payload) if @status.local?
end
def remove_from_media
return unless @status.public_visibility?
- Redis.current.publish('timeline:public:media', @payload)
- Redis.current.publish('timeline:public:local:media', @payload) if @status.local?
- end
-
- def redis
- Redis.current
+ redis.publish('timeline:public:media', @payload)
+ redis.publish('timeline:public:local:media', @payload) if @status.local?
end
end
class Scheduler::FeedCleanupScheduler
include Sidekiq::Worker
+ include Redisable
sidekiq_options unique: :until_executed, retry: 0
def feed_manager
FeedManager.instance
end
-
- def redis
- Redis.current
- end
end