added cached columns for post update count, post upload count, note update count, favorite count to users; fixed tests
This commit is contained in:
@@ -119,6 +119,12 @@ class AnonymousUser
|
||||
def update_column(*params)
|
||||
end
|
||||
|
||||
def increment!(field)
|
||||
end
|
||||
|
||||
def decrement!(field)
|
||||
end
|
||||
|
||||
def role
|
||||
:anonymous
|
||||
end
|
||||
|
||||
@@ -58,6 +58,8 @@ class Note < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def create_version
|
||||
CurrentUser.increment!(:note_update_count)
|
||||
|
||||
versions.create(
|
||||
:updater_id => updater_id,
|
||||
:updater_ip_addr => updater_ip_addr,
|
||||
|
||||
@@ -995,6 +995,8 @@ class Post < ActiveRecord::Base
|
||||
|
||||
module VersionMethods
|
||||
def create_version
|
||||
CurrentUser.increment!(:post_update_count)
|
||||
|
||||
if created_at == updated_at
|
||||
versions.create(
|
||||
:rating => rating,
|
||||
|
||||
@@ -69,6 +69,7 @@ class Upload < ActiveRecord::Base
|
||||
post = convert_to_post
|
||||
post.distribute_files
|
||||
if post.save
|
||||
CurrentUser.increment!(:post_upload_count)
|
||||
update_attributes(:status => "completed", :post_id => post.id)
|
||||
else
|
||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||
|
||||
@@ -182,12 +182,14 @@ class User < ActiveRecord::Base
|
||||
def add_favorite!(post)
|
||||
return if Favorite.exists?(:user_id => id, :post_id => post.id)
|
||||
Favorite.create(:user_id => id, :post_id => post.id)
|
||||
increment!(:favorite_count)
|
||||
post.add_favorite!(self)
|
||||
end
|
||||
|
||||
def remove_favorite!(post)
|
||||
return unless Favorite.exists?(:user_id => id, :post_id => post.id)
|
||||
Favorite.destroy_all(:user_id => id, :post_id => post.id)
|
||||
decrement!(:favorite_count)
|
||||
post.remove_favorite!(self)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,7 +58,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def uploads(template)
|
||||
template.link_to(Post.for_user(user.id).count, template.posts_path(:tags => "uploader:#{user.name}"))
|
||||
template.link_to(user.post_upload_count, template.posts_path(:tags => "uploader:#{user.name}"))
|
||||
end
|
||||
|
||||
def deleted_uploads(template)
|
||||
@@ -66,7 +66,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def favorites(template)
|
||||
template.link_to(Favorite.for_user(user.id).count, template.favorites_path(:user_id => user.id))
|
||||
template.link_to(user.favorite_count, template.favorites_path(:user_id => user.id))
|
||||
end
|
||||
|
||||
def comments(template)
|
||||
@@ -74,11 +74,11 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def post_versions(template)
|
||||
template.link_to(PostVersion.for_user(user.id).count, template.post_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
template.link_to(user.post_update_count, template.post_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def note_versions(template)
|
||||
template.link_to(NoteVersion.for_user(user.id).count, template.note_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
template.link_to(user.note_update_count, template.note_versions_path(:search => {:updater_id_eq => user.id}))
|
||||
end
|
||||
|
||||
def wiki_page_versions(template)
|
||||
|
||||
Reference in New Issue
Block a user