Merge branch 'master' into glitch-soc/merge-upstream
This commit is contained in:
@@ -32,22 +32,23 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
||||
end
|
||||
|
||||
def serializable_hash(options = nil)
|
||||
named_contexts = {}
|
||||
context_extensions = {}
|
||||
options = serialization_options(options)
|
||||
serialized_hash = serializer.serializable_hash(options)
|
||||
serialized_hash = serializer.serializable_hash(options.merge(named_contexts: named_contexts, context_extensions: context_extensions))
|
||||
serialized_hash = serialized_hash.select { |k, _| options[:fields].include?(k) } if options[:fields]
|
||||
serialized_hash = self.class.transform_key_casing!(serialized_hash, instance_options)
|
||||
|
||||
{ '@context' => serialized_context }.merge(serialized_hash)
|
||||
{ '@context' => serialized_context(named_contexts, context_extensions) }.merge(serialized_hash)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def serialized_context
|
||||
def serialized_context(named_contexts_map, context_extensions_map)
|
||||
context_array = []
|
||||
|
||||
serializer_options = serializer.send(:instance_options) || {}
|
||||
named_contexts = [:activitystreams] + serializer._named_contexts.keys + serializer_options.fetch(:named_contexts, {}).keys
|
||||
context_extensions = serializer._context_extensions.keys + serializer_options.fetch(:context_extensions, {}).keys
|
||||
named_contexts = [:activitystreams] + named_contexts_map.keys
|
||||
context_extensions = context_extensions_map.keys
|
||||
|
||||
named_contexts.each do |key|
|
||||
context_array << NAMED_CONTEXT_MAP[key]
|
||||
|
||||
@@ -27,4 +27,12 @@ class ActivityPub::Serializer < ActiveModel::Serializer
|
||||
_context_extensions[extension_name] = true
|
||||
end
|
||||
end
|
||||
|
||||
def serializable_hash(adapter_options = nil, options = {}, adapter_instance = self.class.serialization_adapter_instance)
|
||||
unless adapter_options&.fetch(:named_contexts, nil).nil?
|
||||
adapter_options[:named_contexts].merge!(_named_contexts)
|
||||
adapter_options[:context_extensions].merge!(_context_extensions)
|
||||
end
|
||||
super(adapter_options, options, adapter_instance)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,7 +78,7 @@ class FeedManager
|
||||
reblog_key = key(type, account_id, 'reblogs')
|
||||
|
||||
# Remove any items past the MAX_ITEMS'th entry in our feed
|
||||
redis.zremrangebyrank(timeline_key, '0', (-(FeedManager::MAX_ITEMS + 1)).to_s)
|
||||
redis.zremrangebyrank(timeline_key, 0, -(FeedManager::MAX_ITEMS + 1))
|
||||
|
||||
# Get the score of the REBLOG_FALLOFF'th item in our feed, and stop
|
||||
# tracking anything after it for deduplication purposes.
|
||||
|
||||
@@ -191,6 +191,9 @@ class Request
|
||||
end
|
||||
end
|
||||
|
||||
socks = []
|
||||
addr_by_socket = {}
|
||||
|
||||
addresses.each do |address|
|
||||
begin
|
||||
check_private_address(address)
|
||||
@@ -200,30 +203,45 @@ class Request
|
||||
|
||||
sock.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
|
||||
|
||||
begin
|
||||
sock.connect_nonblock(sockaddr)
|
||||
rescue IO::WaitWritable
|
||||
if IO.select(nil, [sock], nil, Request::TIMEOUT[:connect])
|
||||
begin
|
||||
sock.connect_nonblock(sockaddr)
|
||||
rescue Errno::EISCONN
|
||||
# Yippee!
|
||||
rescue
|
||||
sock.close
|
||||
raise
|
||||
end
|
||||
else
|
||||
sock.close
|
||||
raise HTTP::TimeoutError, "Connect timed out after #{Request::TIMEOUT[:connect]} seconds"
|
||||
end
|
||||
end
|
||||
sock.connect_nonblock(sockaddr)
|
||||
|
||||
# If that hasn't raised an exception, we somehow managed to connect
|
||||
# immediately, close pending sockets and return immediately
|
||||
socks.each(&:close)
|
||||
return sock
|
||||
rescue IO::WaitWritable
|
||||
socks << sock
|
||||
addr_by_socket[sock] = sockaddr
|
||||
rescue => e
|
||||
outer_e = e
|
||||
end
|
||||
end
|
||||
|
||||
until socks.empty?
|
||||
_, available_socks, = IO.select(nil, socks, nil, Request::TIMEOUT[:connect])
|
||||
|
||||
if available_socks.nil?
|
||||
socks.each(&:close)
|
||||
raise HTTP::TimeoutError, "Connect timed out after #{Request::TIMEOUT[:connect]} seconds"
|
||||
end
|
||||
|
||||
available_socks.each do |sock|
|
||||
socks.delete(sock)
|
||||
|
||||
begin
|
||||
sock.connect_nonblock(addr_by_socket[sock])
|
||||
rescue Errno::EISCONN
|
||||
rescue => e
|
||||
sock.close
|
||||
outer_e = e
|
||||
next
|
||||
end
|
||||
|
||||
socks.each(&:close)
|
||||
return sock
|
||||
end
|
||||
end
|
||||
|
||||
if outer_e
|
||||
raise outer_e
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user