From 4f5e0837072af9dde8d831e8c82c17367139e43a Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Fri, 25 Mar 2016 16:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=AA=E4=BA=BA=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=EF=BC=8C=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 3 +- app/views/users/_user_activities.html.erb | 107 +++++++++++----------- 2 files changed, 58 insertions(+), 52 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ed7dad53f..3c779420b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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) # 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(",") blog_ids = "(" + watched_user_blog_ids + ")" diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index 6e590d293..63ae98280 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -54,59 +54,64 @@ sd_create_editor_from_data(<%= user_activity.id %>, null, "100%", "<%= user_activity.class.to_s %>"); }); - <% unless user_activity.act_type == "ProjectCreateInfo" %> - <% act= user_activity.act %> - <% cache (act) do %> - <% case user_activity.container_type.to_s %> - <% when 'Course' %> - <% if act %> - <% case user_activity.act_type.to_s %> - <% when 'HomeworkCommon' %> - <%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:course_activity => 0} %> - <% when 'News' %> - <%= render :partial => 'course_news', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> - <% when 'Message'%> - <%= render :partial => 'course_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> - <% when 'Poll' %> - <%= render :partial => 'course_poll', :locals => {:activity => act, :user_activity_id => user_activity.id} %> - <% when 'Course'%> - <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => act.id} %> - <% end %> - <% end %> - <% when 'Project' %> - <% if act %> - <% case user_activity.act_type.to_s %> - <% when 'Issue' %> - <%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id, :user_id => user_id} %> - <% when 'Message' %> - <%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> - <% when 'ProjectCreateInfo'%> - <%= render :partial => 'project_create', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> - <% end %> - <% end %> - <% when 'Principal' %> - <% if act %> - <% 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 %> - <% 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 %> + <% if user_activity.act_type == "ProjectCreateInfo" %> <%= render :partial => 'project_create', :locals => {:activity => user_activity,:user_activity_id =>user_activity.id} %> - <% end %> + <% else %> + <% act= user_activity.act %> + <%if act %> - <% end %> + <% case user_activity.container_type.to_s %> + <% when 'Course' %> + <% case user_activity.act_type.to_s %> + <% when 'HomeworkCommon' %> + <% cache (act) do %> + <%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:course_activity => 0} %> + <% end %> + <% when 'News' %> + <% cache [act.id, act.comments.count] do %> + <%= render :partial => 'course_news', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> + <% end %> + <% when 'Message'%> + <%= render :partial => 'course_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> + <% when 'Poll' %> + <%= render :partial => 'course_poll', :locals => {:activity => act, :user_activity_id => user_activity.id} %> + <% when 'Course'%> + <% cache (act) do %> + <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => act.id} %> + <%end%> + <% end %> + <% when 'Project' %> + <% case user_activity.act_type.to_s %> + <% when 'Issue' %> + <% cache [act.id, act.journals.count, act.attachments.count] do%> + <%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id, :user_id => user_id} %> + <% end %> + <% when 'Message' %> + <%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> + <% when 'ProjectCreateInfo'%> + <% 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 %> <% if user_activities.count == 10%>