Skip to content

Commit

Permalink
Minor optimization, removing unneeded variables (#546)
Browse files Browse the repository at this point in the history
* Remove unused local variable

delete dead code that became unused due to changes in commit 9937512

* group the assignment to the local variable in the same way as the assignment to association_foreign_key

* move temporary variables, which are only referenced when association_class.paranoid? is true, inside the conditional branch

* simplify association_find_conditions further

---------

Co-authored-by: Mathieu Jobin <mathieu@justbudget.com>
  • Loading branch information
ken3ypa and mathieujobin authored Sep 1, 2023
1 parent 4db17c2 commit 1db8402
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,12 @@ def restore_associated_records(recovery_window_range = nil)
end

if association_data.nil? && association.macro.to_s == "has_one"
association_class_name = association.klass.name

association_foreign_key = if association.options[:through].present?
association.klass.primary_key
else
association.foreign_key
end

if association.type
association_polymorphic_type = association.type
association_find_conditions = { association_polymorphic_type => self.class.name.to_s, association_foreign_key => self.id }
else
association_find_conditions = { association_foreign_key => self.id }
end

association_class = association.klass
if association_class.paranoid?
association_foreign_key = association.options[:through].present? ? association.klass.primary_key : association.foreign_key
association_find_conditions = { association_foreign_key => self.id }
association_find_conditions[association.type] = self.class.name if association.type

association_class.only_deleted.where(association_find_conditions).first
.try!(:restore, recursive: true, :recovery_window_range => recovery_window_range)
end
Expand Down

0 comments on commit 1db8402

Please sign in to comment.