From e168d19635aefc57c540f50228fa973e61d07e9d Mon Sep 17 00:00:00 2001 From: masanbol Date: Sat, 2 Feb 2019 22:41:18 -0500 Subject: [PATCH] Revert "Create Redisable#redis (#9633)" This reverts commit bcfff65195f557dc086470f91b4c90b15c004cf7. --- app/lib/activity_tracker.rb | 6 ++++-- app/lib/activitypub/activity.rb | 5 ++++- app/lib/feed_manager.rb | 9 ++++++--- app/lib/ostatus/activity/base.rb | 6 ++++-- app/lib/potential_friendship_tracker.rb | 8 ++++++-- app/models/concerns/redisable.rb | 11 ----------- app/models/feed.rb | 6 ++++-- app/models/trending_tags.rb | 6 ++++-- app/services/batched_remove_status_service.rb | 5 ++++- app/services/follow_service.rb | 6 ++++-- app/services/post_status_service.rb | 6 ++++-- app/services/remove_status_service.rb | 19 +++++++++++-------- .../scheduler/feed_cleanup_scheduler.rb | 5 ++++- 13 files changed, 59 insertions(+), 39 deletions(-) delete mode 100644 app/models/concerns/redisable.rb diff --git a/app/lib/activity_tracker.rb b/app/lib/activity_tracker.rb index ae3c11b6af5c9..5b497267477af 100644 --- a/app/lib/activity_tracker.rb +++ b/app/lib/activity_tracker.rb @@ -4,8 +4,6 @@ class ActivityTracker EXPIRE_AFTER = 90.days.seconds class << self - include Redisable - def increment(prefix) key = [prefix, current_week].join(':') @@ -22,6 +20,10 @@ def record(prefix, value) private + def redis + Redis.current + end + def current_week Time.zone.today.cweek end diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb index 919678618a316..87318fb1c5c33 100644 --- a/app/lib/activitypub/activity.rb +++ b/app/lib/activitypub/activity.rb @@ -2,7 +2,6 @@ class ActivityPub::Activity include JsonLdHelper - include Redisable def initialize(json, account, **options) @json = json @@ -71,6 +70,10 @@ def object_uri @object_uri ||= value_or_id(@object) end + def redis + Redis.current + end + def distribute(status) crawl_links(status) diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index d77cdb3a3cc20..f99df33e54f0d 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -4,7 +4,6 @@ class FeedManager include Singleton - include Redisable MAX_ITEMS = 400 @@ -36,7 +35,7 @@ def push_to_home(account, status) def unpush_from_home(account, status) return false unless remove_from_feed(:home, account.id, status) - redis.publish("timeline:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s)) + Redis.current.publish("timeline:#{account.id}", Oj.dump(event: :delete, payload: status.id.to_s)) true end @@ -54,7 +53,7 @@ def push_to_list(list, status) def unpush_from_list(list, status) return false unless remove_from_feed(:list, list.id, status) - redis.publish("timeline:list:#{list.id}", Oj.dump(event: :delete, payload: status.id.to_s)) + Redis.current.publish("timeline:list:#{list.id}", Oj.dump(event: :delete, payload: status.id.to_s)) true end @@ -143,6 +142,10 @@ def populate_feed(account) private + def redis + Redis.current + end + def push_update_required?(timeline_id) redis.exists("subscribed:#{timeline_id}") end diff --git a/app/lib/ostatus/activity/base.rb b/app/lib/ostatus/activity/base.rb index db70f19980cd5..c5933f3adfecf 100644 --- a/app/lib/ostatus/activity/base.rb +++ b/app/lib/ostatus/activity/base.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class OStatus::Activity::Base - include Redisable - def initialize(xml, account = nil, **options) @xml = xml @account = account @@ -68,4 +66,8 @@ def find_activitypub_status(uri, href) Status.find_by(uri: uri) end end + + def redis + Redis.current + end end diff --git a/app/lib/potential_friendship_tracker.rb b/app/lib/potential_friendship_tracker.rb index 188aa4a275657..017a9748d5f97 100644 --- a/app/lib/potential_friendship_tracker.rb +++ b/app/lib/potential_friendship_tracker.rb @@ -11,8 +11,6 @@ class PotentialFriendshipTracker }.freeze class << self - include Redisable - def record(account_id, target_account_id, action) return if account_id == target_account_id @@ -33,5 +31,11 @@ def get(account_id, limit: 20, offset: 0) return [] if account_ids.empty? Account.searchable.where(id: account_ids) end + + private + + def redis + Redis.current + end end end diff --git a/app/models/concerns/redisable.rb b/app/models/concerns/redisable.rb deleted file mode 100644 index c6cf9735960c1..0000000000000 --- a/app/models/concerns/redisable.rb +++ /dev/null @@ -1,11 +0,0 @@ -# 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 0e8943ff863bd..5bce88f25522d 100644 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class Feed - include Redisable - def initialize(type, id) @type = type @id = id @@ -29,4 +27,8 @@ def from_redis(limit, max_id, since_id, min_id) 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 148535c2121e0..3a8be21649b93 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -7,8 +7,6 @@ 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? @@ -61,5 +59,9 @@ def disallowed_hashtags @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 diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index cd3b14e08e34e..2e61904fc770f 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -2,7 +2,6 @@ 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 @@ -110,6 +109,10 @@ def batch_salmon_slaps(status) 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) diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 92d8c864a7de1..9d36a1449dff3 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -1,8 +1,6 @@ # 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) @@ -69,6 +67,10 @@ def direct_follow(source_account, target_account, reblogs: true) 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 diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 686b10c5817c3..9959bb1fbf7d0 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -1,8 +1,6 @@ # 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 @@ -112,6 +110,10 @@ def process_hashtags_service ProcessHashtagsService.new end + def redis + Redis.current + end + def scheduled? @scheduled_at.present? end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index 28c5224b01184..11d28e783d04c 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -2,7 +2,6 @@ class RemoveStatusService < BaseService include StreamEntryRenderer - include Redisable def call(status, **options) @payload = Oj.dump(event: :delete, payload: status.id.to_s) @@ -56,7 +55,7 @@ def remove_from_lists def remove_from_affected @mentions.map(&:account).select(&:local?).each do |account| - redis.publish("timeline:#{account.id}", @payload) + Redis.current.publish("timeline:#{account.id}", @payload) end end @@ -134,22 +133,26 @@ def remove_from_hashtags return unless @status.public_visibility? @tags.each do |hashtag| - redis.publish("timeline:hashtag:#{hashtag}", @payload) - redis.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local? + Redis.current.publish("timeline:hashtag:#{hashtag}", @payload) + Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local? end end def remove_from_public return unless @status.public_visibility? - redis.publish('timeline:public', @payload) - redis.publish('timeline:public:local', @payload) if @status.local? + Redis.current.publish('timeline:public', @payload) + Redis.current.publish('timeline:public:local', @payload) if @status.local? end def remove_from_media return unless @status.public_visibility? - redis.publish('timeline:public:media', @payload) - redis.publish('timeline:public:local:media', @payload) if @status.local? + Redis.current.publish('timeline:public:media', @payload) + Redis.current.publish('timeline:public:local:media', @payload) if @status.local? + end + + def redis + Redis.current end end diff --git a/app/workers/scheduler/feed_cleanup_scheduler.rb b/app/workers/scheduler/feed_cleanup_scheduler.rb index bf5e20757007d..cd22734180572 100644 --- a/app/workers/scheduler/feed_cleanup_scheduler.rb +++ b/app/workers/scheduler/feed_cleanup_scheduler.rb @@ -2,7 +2,6 @@ class Scheduler::FeedCleanupScheduler include Sidekiq::Worker - include Redisable sidekiq_options unique: :until_executed, retry: 0 @@ -58,4 +57,8 @@ def inactive_list_ids def feed_manager FeedManager.instance end + + def redis + Redis.current + end end