Refactor how Redis locks are created (#18400)
* Refactor how Redis locks are created * Fix autorelease duration on account deletion lock
This commit is contained in:
parent
12535568f7
commit
6cf57c6765
16 changed files with 112 additions and 179 deletions
|
@ -3,6 +3,7 @@
|
|||
class RemoveStatusService < BaseService
|
||||
include Redisable
|
||||
include Payloadable
|
||||
include Lockable
|
||||
|
||||
# Delete a status
|
||||
# @param [Status] status
|
||||
|
@ -17,37 +18,33 @@ class RemoveStatusService < BaseService
|
|||
@account = status.account
|
||||
@options = options
|
||||
|
||||
RedisLock.acquire(lock_options) do |lock|
|
||||
if lock.acquired?
|
||||
@status.discard
|
||||
with_lock("distribute:#{@status.id}") do
|
||||
@status.discard
|
||||
|
||||
remove_from_self if @account.local?
|
||||
remove_from_followers
|
||||
remove_from_lists
|
||||
remove_from_self if @account.local?
|
||||
remove_from_followers
|
||||
remove_from_lists
|
||||
|
||||
# There is no reason to send out Undo activities when the
|
||||
# cause is that the original object has been removed, since
|
||||
# original object being removed implicitly removes reblogs
|
||||
# of it. The Delete activity of the original is forwarded
|
||||
# separately.
|
||||
remove_from_remote_reach if @account.local? && !@options[:original_removed]
|
||||
# There is no reason to send out Undo activities when the
|
||||
# cause is that the original object has been removed, since
|
||||
# original object being removed implicitly removes reblogs
|
||||
# of it. The Delete activity of the original is forwarded
|
||||
# separately.
|
||||
remove_from_remote_reach if @account.local? && !@options[:original_removed]
|
||||
|
||||
# Since reblogs don't mention anyone, don't get reblogged,
|
||||
# favourited and don't contain their own media attachments
|
||||
# or hashtags, this can be skipped
|
||||
unless @status.reblog?
|
||||
remove_from_mentions
|
||||
remove_reblogs
|
||||
remove_from_hashtags
|
||||
remove_from_public
|
||||
remove_from_media if @status.with_media?
|
||||
remove_media
|
||||
end
|
||||
|
||||
@status.destroy! if permanently?
|
||||
else
|
||||
raise Mastodon::RaceConditionError
|
||||
# Since reblogs don't mention anyone, don't get reblogged,
|
||||
# favourited and don't contain their own media attachments
|
||||
# or hashtags, this can be skipped
|
||||
unless @status.reblog?
|
||||
remove_from_mentions
|
||||
remove_reblogs
|
||||
remove_from_hashtags
|
||||
remove_from_public
|
||||
remove_from_media if @status.with_media?
|
||||
remove_media
|
||||
end
|
||||
|
||||
@status.destroy! if permanently?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -144,8 +141,4 @@ class RemoveStatusService < BaseService
|
|||
def permanently?
|
||||
@options[:immediate] || !(@options[:preserve] || @status.reported?)
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: redis, key: "distribute:#{@status.id}", autorelease: 5.minutes.seconds }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue