From f80f04e379a8e0eef1bd72432c6a252d3559a9c6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 24 Nov 2007 15:14:32 +0000 Subject: [PATCH] Slight optimization in User#role_for_project. git-svn-id: http://redmine.rubyforge.org/svn/trunk@928 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/user.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 5297b31b0..37512fda0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -178,14 +178,16 @@ class User < ActiveRecord::Base def role_for_project(project) # No role on archived projects return nil unless project && project.active? - # Find project membership - membership = memberships.detect {|m| m.project_id == project.id} - if membership - membership.role - elsif logged? - Role.non_member + if logged? + # Find project membership + membership = memberships.detect {|m| m.project_id == project.id} + if membership + membership.role + else + @role_non_member ||= Role.non_member + end else - Role.anonymous + @role_anonymous ||= Role.anonymous end end