Permalink
Browse files

Don't create local vars.

  • Loading branch information...
miloops authored and tenderlove committed Nov 20, 2010
1 parent 6ffe0ef commit d29d793c9096a732274298cdba07c654e9128484
Showing with 1 addition and 4 deletions.
  1. +1 −4 activerecord/lib/active_record/locking/optimistic.rb
@@ -110,12 +110,9 @@ def destroy #:nodoc:
return super unless locking_enabled?
if persisted?
- lock_col = self.class.locking_column
- previous_value = send(lock_col).to_i
-
table = self.class.arel_table
predicate = table[self.class.primary_key].eq(id)
- predicate = predicate.and(table[self.class.locking_column].eq(previous_value))
+ predicate = predicate.and(table[self.class.locking_column].eq(send(self.class.locking_column).to_i))

This comment has been minimized.

Show comment Hide comment
@aermolaev

aermolaev Nov 24, 2010

Code duplication. May be better that?

lock_col = self.class.locking_column
predicate = predicate.and(table[lock_col].eq(send(lock_col).to_i))

@aermolaev

aermolaev Nov 24, 2010

Code duplication. May be better that?

lock_col = self.class.locking_column
predicate = predicate.and(table[lock_col].eq(send(lock_col).to_i))

This comment has been minimized.

Show comment Hide comment
@tenderlove

tenderlove Nov 24, 2010

Member

I agree. That would have been better.

@tenderlove

tenderlove Nov 24, 2010

Member

I agree. That would have been better.

This comment has been minimized.

Show comment Hide comment
@miloops

miloops Nov 24, 2010

Contributor

yeah, i saw lock_col was used just once but instead removing it would be better to reuse it. previous_value should still be removed tho.

@miloops

miloops Nov 24, 2010

Contributor

yeah, i saw lock_col was used just once but instead removing it would be better to reuse it. previous_value should still be removed tho.

affected_rows = self.class.unscoped.where(predicate).delete_all

0 comments on commit d29d793

Please sign in to comment.