Fix #2402 - Add Idempotency-Key header to PostStatusService that prevents (#2419)

duplicates. Web UI regenerates UUID for that header every time the compose
form is changed or successfully submitted

Also, fix Farsi i18n overwriting the English one
This commit is contained in:
Eugen Rochko 2017-04-25 15:04:49 +02:00 committed by GitHub
parent 3ea5b948a4
commit 8b5179d006
7 changed files with 67 additions and 13 deletions

View file

@ -11,8 +11,14 @@ class PostStatusService < BaseService
# @option [String] :spoiler_text
# @option [Enumerable] :media_ids Optional array of media IDs to attach
# @option [Doorkeeper::Application] :application
# @option [String] :idempotency Optional idempotency key
# @return [Status]
def call(account, text, in_reply_to = nil, options = {})
if options[:idempotency].present?
existing_id = redis.get("idempotency:status:#{account.id}:#{options[:idempotency]}")
return Status.find(existing_id) if existing_id
end
media = validate_media!(options[:media_ids])
status = account.statuses.create!(text: text,
thread: in_reply_to,
@ -30,6 +36,10 @@ class PostStatusService < BaseService
DistributionWorker.perform_async(status.id)
Pubsubhubbub::DistributionWorker.perform_async(status.stream_entry.id)
if options[:idempotency].present?
redis.setex("idempotency:status:#{account.id}:#{options[:idempotency]}", 3_600, status.id)
end
status
end
@ -63,4 +73,8 @@ class PostStatusService < BaseService
def process_hashtags_service
@process_hashtags_service ||= ProcessHashtagsService.new
end
def redis
Redis.current
end
end