Skip to content

Commit

Permalink
Optimization: Stop after the first detected condition
Browse files Browse the repository at this point in the history
  • Loading branch information
CloCkWeRX committed Dec 1, 2016
1 parent 5069a62 commit 4dc263a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/users/user.rb
Expand Up @@ -160,12 +160,12 @@ def check_if_current_user
# Prevent deleting a user unless she has no artifacts left.
#----------------------------------------------------------------------------
def check_if_has_related_assets
artifacts = %w(Account Campaign Lead Contact Opportunity Comment Task).inject(0) do |sum, asset|
sum = %w(Account Campaign Lead Contact Opportunity Comment Task).detect do |asset|
klass = asset.constantize
sum += klass.assigned_to(self).count if asset != "Comment"
sum += klass.created_by(self).count

asset != "Comment" && klass.assigned_to(self).exists? || klass.created_by(self).exists?
end
artifacts == 0
sum == nil
end

# Define class methods
Expand Down

0 comments on commit 4dc263a

Please sign in to comment.