diff --git a/app/models/user.rb b/app/models/user.rb index a484d3549..b258f0f00 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -517,6 +517,8 @@ class User < ActiveRecord::Base options ||= {} options[:except] ||= [] options[:except] += hidden_attributes + options[:methods] ||= [] + options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count] super(options) end @@ -538,6 +540,28 @@ class User < ActiveRecord::Base end end + module CountMethods + def wiki_page_version_count + WikiPageVersion.for_user(id).count + end + + def artist_version_count + ArtistVersion.for_user(id).count + end + + def pool_version_count + PoolVersion.for_user(id).count + end + + def forum_post_count + ForumPost.for_user(id).count + end + + def comment_count + Comment.for_creator(id).count + end + end + module SearchMethods def named(name) where("lower(name) = ?", name) @@ -628,6 +652,7 @@ class User < ActiveRecord::Base include LimitMethods include InvitationMethods include ApiMethods + include CountMethods extend SearchMethods def initialize_default_image_size diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 711a908c1..608b01baa 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -80,7 +80,7 @@ class UserPresenter end def comment_count(template) - template.link_to(Comment.for_creator(user.id).count, template.comments_path(:search => {:creator_id => user.id}, :group_by => "comment")) + template.link_to(user.comment_count, template.comments_path(:search => {:creator_id => user.id}, :group_by => "comment")) end def commented_posts_count(template) @@ -100,19 +100,19 @@ class UserPresenter end def wiki_page_version_count(template) - template.link_to(WikiPageVersion.for_user(user.id).count, template.wiki_page_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.wiki_page_version_count, template.wiki_page_versions_path(:search => {:updater_id => user.id})) end def artist_version_count(template) - template.link_to(ArtistVersion.for_user(user.id).count, template.artist_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.artist_version_count, template.artist_versions_path(:search => {:updater_id => user.id})) end def forum_post_count(template) - template.link_to(ForumPost.for_user(user.id).count, template.forum_posts_path(:search => {:creator_id => user.id})) + template.link_to(user.forum_post_count, template.forum_posts_path(:search => {:creator_id => user.id})) end def pool_version_count(template) - template.link_to(PoolVersion.for_user(user.id).count, template.pool_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.pool_version_count, template.pool_versions_path(:search => {:updater_id => user.id})) end def inviter(template)