优化个人主页,缓存设置

alan_develop
alan 9 years ago
parent aeb694a68e
commit 4f5e083707

@ -1250,7 +1250,8 @@ class UsersController < ApplicationController
# @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
# blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
# 减少数据库交互 # 减少数据库交互
user_ids = "(" + @user.id.to_s + "," + User.watched_by(@user.id).map{|u| u.id }.join(',') + ")" watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + @user.id.to_s + watched_user_ids + ")"
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
blog_ids = "(" + watched_user_blog_ids + ")" blog_ids = "(" + watched_user_blog_ids + ")"

@ -54,59 +54,64 @@
sd_create_editor_from_data(<%= user_activity.id %>, null, "100%", "<%= user_activity.class.to_s %>"); sd_create_editor_from_data(<%= user_activity.id %>, null, "100%", "<%= user_activity.class.to_s %>");
}); });
</script> </script>
<% unless user_activity.act_type == "ProjectCreateInfo" %> <% if user_activity.act_type == "ProjectCreateInfo" %>
<% act= user_activity.act %> <%= render :partial => 'project_create', :locals => {:activity => user_activity,:user_activity_id =>user_activity.id} %>
<% cache (act) do %> <% else %>
<% case user_activity.container_type.to_s %> <% act= user_activity.act %>
<% when 'Course' %> <%if act %>
<% if act %>
<% case user_activity.act_type.to_s %> <% case user_activity.container_type.to_s %>
<% when 'HomeworkCommon' %> <% when 'Course' %>
<%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:course_activity => 0} %> <% case user_activity.act_type.to_s %>
<% when 'News' %> <% when 'HomeworkCommon' %>
<%= render :partial => 'course_news', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> <% cache (act) do %>
<% when 'Message'%> <%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:course_activity => 0} %>
<%= render :partial => 'course_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> <% end %>
<% when 'Poll' %> <% when 'News' %>
<%= render :partial => 'course_poll', :locals => {:activity => act, :user_activity_id => user_activity.id} %> <% cache [act.id, act.comments.count] do %>
<% when 'Course'%> <%= render :partial => 'course_news', :locals => {:activity => act,:user_activity_id =>user_activity.id} %>
<%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => act.id} %> <% end %>
<% end %> <% when 'Message'%>
<% end %> <%= render :partial => 'course_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %>
<% when 'Project' %> <% when 'Poll' %>
<% if act %> <%= render :partial => 'course_poll', :locals => {:activity => act, :user_activity_id => user_activity.id} %>
<% case user_activity.act_type.to_s %> <% when 'Course'%>
<% when 'Issue' %> <% cache (act) do %>
<%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id, :user_id => user_id} %> <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => act.id} %>
<% when 'Message' %> <%end%>
<%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> <% end %>
<% when 'ProjectCreateInfo'%> <% when 'Project' %>
<%= render :partial => 'project_create', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> <% case user_activity.act_type.to_s %>
<% end %> <% when 'Issue' %>
<% end %> <% cache [act.id, act.journals.count, act.attachments.count] do%>
<% when 'Principal' %> <%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id, :user_id => user_id} %>
<% if act %> <% end %>
<% case user_activity.act_type.to_s %> <% when 'Message' %>
<% when 'JournalsForMessage' %> <%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %>
<% unless act.private == 1 && (!User.current || (User.current && act.jour_id != User.current.id && act.user_id != User.current.id)) %> <% when 'ProjectCreateInfo'%>
<%= render :partial => 'user_journalsformessage', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_activity=>1} %> <% cache (act) do %>
<%= render :partial => 'project_create', :locals => {:activity => act,:user_activity_id =>user_activity.id} %>
<% end %>
<% end %>
<% when 'Principal' %>
<% case user_activity.act_type.to_s %>
<% when 'JournalsForMessage' %>
<% unless act.private == 1 && (!User.current || (User.current && act.jour_id != User.current.id && act.user_id != User.current.id)) %>
<%= render :partial => 'user_journalsformessage', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_activity=>1} %>
<% end %>
<% end %>
<% when 'Blog'%>
<% cache (act) do %>
<% case user_activity.act_type.to_s %>
<% when 'BlogComment' %>
<%= render :partial => 'user_blog', :locals => {:activity => act,:user_activity_id =>user_activity.id} %>
<% end %>
<% end %>
<% end %> <% end %>
<% end %>
<% end %>
<% end %> <% end %>
<% when 'Blog'%>
<%if act %>
<% case user_activity.act_type.to_s %>
<% when 'BlogComment' %>
<%= render :partial => 'user_blog', :locals => {:activity => act,:user_activity_id =>user_activity.id} %>
<% end %>
<% end %>
<% end %>
<% end %>
<% else %>
<%= render :partial => 'project_create', :locals => {:activity => user_activity,:user_activity_id =>user_activity.id} %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>
<% if user_activities.count == 10%> <% if user_activities.count == 10%>

Loading…
Cancel
Save