Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Redis#exists calls to Redis#exists? to avoid deprecation warning #14191

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@
/log/*
!/log/.keep
/tmp
coverage
public/system
public/assets
public/packs
public/packs-test
/coverage
/public/system
/public/assets
/public/packs
/public/packs-test
.env
.env.production
.env.development
node_modules/
build/
/node_modules/
/build/

# Ignore Vagrant files
.vagrant/

# Ignore Capistrano customizations
config/deploy/*
/config/deploy/*

# Ignore IDE files
.vscode/
.idea/

# Ignore postgres + redis + elasticsearch volume optionally created by docker-compose
postgres
redis
elasticsearch
/postgres
/redis
/elasticsearch

# ignore Helm lockfile, dependency charts, and local values file
chart/Chart.lock
chart/charts/*.tgz
chart/values.yaml
/chart/Chart.lock
/chart/charts/*.tgz
/chart/values.yaml

# Ignore Apple files
.DS_Store
Expand Down
7 changes: 2 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ GEM
rack (>= 1.0, < 3)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-protection (2.0.8.1)
rack
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
Expand Down Expand Up @@ -570,11 +568,10 @@ GEM
nokogiri (>= 1.8.0)
nokogumbo (~> 2.0)
semantic_range (2.3.0)
sidekiq (6.0.7)
sidekiq (6.1.0)
connection_pool (>= 2.2.2)
rack (~> 2.0)
rack-protection (>= 2.0.0)
redis (>= 4.1.0)
redis (>= 4.2.0)
sidekiq-bulk (0.2.0)
sidekiq
sidekiq-scheduler (3.0.1)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def distribute_to_followers(status)
end

def delete_arrived_first?(uri)
redis.exists("delete_upon_arrival:#{@account.id}:#{uri}")
redis.exists?("delete_upon_arrival:#{@account.id}:#{uri}")
end

def delete_later!(uri)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/move.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def target_uri
end

def processed?
redis.exists("move_in_progress:#{@account.id}")
redis.exists?("move_in_progress:#{@account.id}")
end

def mark_as_processing!
Expand Down
2 changes: 1 addition & 1 deletion app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def populate_feed(account)
private

def push_update_required?(timeline_id)
redis.exists("subscribed:#{timeline_id}")
redis.exists?("subscribed:#{timeline_id}")
end

def blocks_or_mutes?(receiver_id, account_ids, context)
Expand Down
2 changes: 1 addition & 1 deletion app/models/account_conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def push_to_streaming_api
end

def subscribed_to_timeline?
Redis.current.exists("subscribed:#{streaming_channel}")
Redis.current.exists?("subscribed:#{streaming_channel}")
end

def streaming_channel
Expand Down
5 changes: 1 addition & 4 deletions app/models/encrypted_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ class EncryptedMessage < ApplicationRecord
private

def push_to_streaming_api
Rails.logger.info(streaming_channel)
Rails.logger.info(subscribed_to_timeline?)

return if destroyed? || !subscribed_to_timeline?

PushEncryptedMessageWorker.perform_async(id)
end

def subscribed_to_timeline?
Redis.current.exists("subscribed:#{streaming_channel}")
Redis.current.exists?("subscribed:#{streaming_channel}")
end

def streaming_channel
Expand Down
2 changes: 1 addition & 1 deletion app/models/home_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def initialize(account)
end

def regenerating?
redis.exists("account:#{@id}:regeneration")
redis.exists?("account:#{@id}:regeneration")
end
end
2 changes: 1 addition & 1 deletion app/workers/publish_announcement_reaction_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def perform(announcement_id, name)
payload = Oj.dump(event: :'announcement.reaction', payload: payload)

FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}")
end
rescue ActiveRecord::RecordNotFound
true
Expand Down
2 changes: 1 addition & 1 deletion app/workers/publish_scheduled_announcement_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def perform(announcement_id)
payload = Oj.dump(event: :announcement, payload: payload)

FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}")
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/workers/unpublish_announcement_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def perform(announcement_id)
payload = Oj.dump(event: :'announcement.delete', payload: announcement_id.to_s)

FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}")
end
end
end
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Bundler.require(*Rails.groups)

require_relative '../app/lib/exceptions'
require_relative '../lib/redis/namespace_extensions'
require_relative '../lib/paperclip/url_generator_extensions'
require_relative '../lib/paperclip/attachment_extensions'
require_relative '../lib/paperclip/media_type_spoof_detector_extensions'
Expand Down
2 changes: 0 additions & 2 deletions config/initializers/redis.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

Redis.exists_returns_integer = false

redis_connection = Redis.new(
url: ENV['REDIS_URL'],
driver: :hiredis
Expand Down
12 changes: 12 additions & 0 deletions lib/redis/namespace_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class Redis
module NamespaceExtensions
def exists?(*args, &block)
call_with_namespace('exists?', *args, &block)
end
end
end

Redis::Namespace::COMMANDS['exists?'] = [:first]
Redis::Namespace.prepend(Redis::NamespaceExtensions)
Comment on lines +3 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. I'm not sure I understand that. The fix in redis-namespace seems to be only adding "exists?" => [:all] to the namespaced commands? resque/redis-namespace#171

Also, does using “exists?” change the Redis version requirements in any way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, exists? isn't a Redis command, it's a Ruby command on the Redis library.

And no, the fix is not that, because at evaluation time the class iterates over that constant to define_method for each. If you just add another item to the constant, it won't define the method. But the addition to constant is also required because it controls the behaviour with the :first option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I can see the define_method thing. Shouldn't it be = [:all] though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used whatever the definition for exists was using.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, according to Redis' documentation, EXISTS can take multiple keys, so it should be :all, as the aforementioned PR does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Well, we never use that command with more than one argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean we can never use it with more than one argument?

Copy link
Member Author

@Gargron Gargron Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Where were you going to use Redis#exists? with more than one argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. Sounds like bad practice and stuff which could become confusing in the future.