Skip to content

Commit 8f642fb

Browse files
committed
Remove condition for #shadow_delete_documents
On the row where #shadow_delete_documents is called, topic.persisted? also returns true for newly created topics since we just saved. I don't think we really need a condition because docs_to_delete would be blank for newly created topics. If we do want one, using topic.previously_new_record? wouldn't work because topic gets updated when running #attach_files, so we would have to do something like "new_record = topic.new_record?" before calling topic.save_with_tags and then use "unless new_record".
1 parent 72c55b1 commit 8f642fb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

app/services/topics/mutator.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def mutate
5353
ActiveRecord::Base.transaction do
5454
topic.save_with_tags(params)
5555
attach_files(document_signed_ids)
56-
# topic.persisted? means that we are updating existing topic and documents can be removed
57-
shadow_delete_documents(docs_to_delete) if topic.persisted?
56+
shadow_delete_documents(docs_to_delete)
5857
rename_files(document_signed_ids)
5958
# document_signed_ids.any? means that some new documents were attached and we need to sync them
6059
sync_docs_for_topic_updates if document_signed_ids.any?
@@ -75,7 +74,7 @@ def attach_files(signed_ids)
7574
def rename_files(signed_ids)
7675
return if signed_ids.blank?
7776
signed_ids.each do |signed_id|
78-
document = topic.documents.find { |doc| doc.blob.signed_id == signed_id }
77+
document = topic.documents.find { |doc| doc.blob.signed_id == signed_id }
7978
next unless document
8079

8180
new_filename = topic.custom_file_name(document)

0 commit comments

Comments
 (0)