summaryrefslogtreecommitdiffstats
path: root/app/models/principal.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-01-03 18:28:45 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-01-03 18:28:45 +0000
commitf8df935dcada4c45eb09e7f9c7044a54db198d9c (patch)
tree14ed11f6a53b6e598aa8b02e5bab356ad90865d1 /app/models/principal.rb
parentfd067bc9dfdb65c84654d22aca0fc3e8f57f947a (diff)
downloadredmine-f8df935dcada4c45eb09e7f9c7044a54db198d9c.tar.gz
redmine-f8df935dcada4c45eb09e7f9c7044a54db198d9c.zip
Speeds up rendering of the project list for users who belong to hundreds of projects.
git-svn-id: http://svn.redmine.org/redmine/trunk@16123 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/principal.rb')
-rw-r--r--app/models/principal.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb
index f3e0a3d4d..15cf69961 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -108,6 +108,11 @@ class Principal < ActiveRecord::Base
before_create :set_default_empty_values
+ def reload(*args)
+ @project_ids = nil
+ super
+ end
+
def name(formatter = nil)
to_s
end
@@ -124,9 +129,14 @@ class Principal < ActiveRecord::Base
Principal.visible(user).where(:id => id).first == self
end
- # Return true if the principal is a member of project
+ # Returns true if the principal is a member of project
def member_of?(project)
- projects.to_a.include?(project)
+ project.is_a?(Project) && project_ids.include?(project.id)
+ end
+
+ # Returns an array of the project ids that the principal is a member of
+ def project_ids
+ @project_ids ||= super.freeze
end
def <=>(principal)