Skip to content

Commit

Permalink
Ensure a document is always created
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasleese committed Dec 30, 2016
1 parent f096353 commit 211648c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app/commands/v2/put_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def call
end

PathReservation.reserve_base_path!(base_path, publishing_app) if content_with_base_path?
content_item = find_previously_drafted_content_item
content_item = previously_drafted_content_item

if content_item
update_existing_content_item(content_item)
Expand Down Expand Up @@ -105,11 +105,8 @@ def create_or_update_access_limit(content_item, users:)
end
end

def find_previously_drafted_content_item
ContentItem.find_by(
document_id: pessimistic_document_scope.pluck(:id),
state: "draft",
)
def previously_drafted_content_item
ContentItem.find_by(document: document, state: "draft")
end

def clear_draft_items_of_same_locale_and_base_path
Expand Down Expand Up @@ -168,8 +165,8 @@ def user_facing_version_number_for_new_draft
end
end

def pessimistic_document_scope
Document.where(content_id: content_id, locale: locale).lock
def document
Document.find_or_create_by(content_id: content_id, locale: locale)
end

def previously_published_item
Expand Down

0 comments on commit 211648c

Please sign in to comment.