diff options
author | Starfall <us@starfall.systems> | 2022-04-29 09:20:51 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-04-29 09:20:51 -0500 |
commit | 4eb291e5db6114c8aa564f0c9e7f04d13805b5cc (patch) | |
tree | 1a6affcf635974ccf6d0f650a3bbe2be75c7929e /app/models | |
parent | bcaacc42334d75bd361f330989041a9beba101a9 (diff) | |
parent | 252deefe3433d0cedafd973becd0d85b5182eb49 (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 6 | ||||
-rw-r--r-- | app/models/account_conversation.rb | 4 | ||||
-rw-r--r-- | app/models/account_suggestions/global_source.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/account_finder_concern.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/redisable.rb | 2 | ||||
-rw-r--r-- | app/models/custom_filter.rb | 3 | ||||
-rw-r--r-- | app/models/encrypted_message.rb | 3 | ||||
-rw-r--r-- | app/models/follow_recommendation_filter.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 3 |
9 files changed, 23 insertions, 8 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 1966c5a48..068ee7ae9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -561,6 +561,12 @@ class Account < ApplicationRecord before_validation :prepare_username, on: :create before_destroy :clean_feed_manager + def ensure_keys! + return unless local? && private_key.blank? && public_key.blank? + generate_keys + save! + end + private def prepare_contents diff --git a/app/models/account_conversation.rb b/app/models/account_conversation.rb index 56fd13543..45e74bbeb 100644 --- a/app/models/account_conversation.rb +++ b/app/models/account_conversation.rb @@ -14,6 +14,8 @@ # class AccountConversation < ApplicationRecord + include Redisable + after_commit :push_to_streaming_api belongs_to :account @@ -109,7 +111,7 @@ class AccountConversation < ApplicationRecord end def subscribed_to_timeline? - Redis.current.exists?("subscribed:#{streaming_channel}") + redis.exists?("subscribed:#{streaming_channel}") end def streaming_channel diff --git a/app/models/account_suggestions/global_source.rb b/app/models/account_suggestions/global_source.rb index 7bca530d4..651041d67 100644 --- a/app/models/account_suggestions/global_source.rb +++ b/app/models/account_suggestions/global_source.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class AccountSuggestions::GlobalSource < AccountSuggestions::Source + include Redisable + def key :global end @@ -28,7 +30,7 @@ class AccountSuggestions::GlobalSource < AccountSuggestions::Source end def account_ids_for_locale(locale) - Redis.current.zrevrange("follow_recommendations:#{locale}", 0, -1).map(&:to_i) + redis.zrevrange("follow_recommendations:#{locale}", 0, -1).map(&:to_i) end def to_ordered_list_key(account) diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb index 0dadddad1..e8b804934 100644 --- a/app/models/concerns/account_finder_concern.rb +++ b/app/models/concerns/account_finder_concern.rb @@ -13,7 +13,7 @@ module AccountFinderConcern end def representative - Account.find(-99) + Account.find(-99).tap(&:ensure_keys!) rescue ActiveRecord::RecordNotFound Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain) end diff --git a/app/models/concerns/redisable.rb b/app/models/concerns/redisable.rb index c6cf97359..cce8efb86 100644 --- a/app/models/concerns/redisable.rb +++ b/app/models/concerns/redisable.rb @@ -6,6 +6,6 @@ module Redisable private def redis - Redis.current + Thread.current[:redis] ||= RedisConfiguration.new.connection end end diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index 9d0f3729b..8e3476794 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -24,6 +24,7 @@ class CustomFilter < ApplicationRecord ).freeze include Expireable + include Redisable belongs_to :account @@ -51,7 +52,7 @@ class CustomFilter < ApplicationRecord def remove_cache Rails.cache.delete("filters:#{account_id}") - Redis.current.publish("timeline:#{account_id}", Oj.dump(event: :filters_changed)) + redis.publish("timeline:#{account_id}", Oj.dump(event: :filters_changed)) end def context_must_be_valid diff --git a/app/models/encrypted_message.rb b/app/models/encrypted_message.rb index aa4182b4e..7b4e32283 100644 --- a/app/models/encrypted_message.rb +++ b/app/models/encrypted_message.rb @@ -19,6 +19,7 @@ class EncryptedMessage < ApplicationRecord self.inheritance_column = nil include Paginable + include Redisable scope :up_to, ->(id) { where(arel_table[:id].lteq(id)) } @@ -38,7 +39,7 @@ class EncryptedMessage < ApplicationRecord end def subscribed_to_timeline? - Redis.current.exists?("subscribed:#{streaming_channel}") + redis.exists?("subscribed:#{streaming_channel}") end def streaming_channel diff --git a/app/models/follow_recommendation_filter.rb b/app/models/follow_recommendation_filter.rb index acf03cd84..531332614 100644 --- a/app/models/follow_recommendation_filter.rb +++ b/app/models/follow_recommendation_filter.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class FollowRecommendationFilter + include Redisable + KEYS = %i( language status @@ -17,7 +19,7 @@ class FollowRecommendationFilter if params['status'] == 'suppressed' Account.joins(:follow_recommendation_suppression).order(FollowRecommendationSuppression.arel_table[:id].desc).to_a else - account_ids = Redis.current.zrevrange("follow_recommendations:#{@language}", 0, -1).map(&:to_i) + account_ids = redis.zrevrange("follow_recommendations:#{@language}", 0, -1).map(&:to_i) accounts = Account.where(id: account_ids).index_by(&:id) account_ids.map { |id| accounts[id] }.compact diff --git a/app/models/user.rb b/app/models/user.rb index 5c1f9504a..b38de74b8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,6 +52,7 @@ class User < ApplicationRecord include Settings::Extend include UserRoles + include Redisable # The home and list feeds will be stored in Redis for this amount # of time, and status fan-out to followers will include only people @@ -464,7 +465,7 @@ class User < ApplicationRecord end def regenerate_feed! - RegenerationWorker.perform_async(account_id) if Redis.current.set("account:#{account_id}:regeneration", true, nx: true, ex: 1.day.seconds) + RegenerationWorker.perform_async(account_id) if redis.set("account:#{account_id}:regeneration", true, nx: true, ex: 1.day.seconds) end def needs_feed_update? |