From 312955e5dc80027e05aeb20aef7094fa38f4f94e Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 11 Sep 2015 16:45:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20150911064528_alter_user_activities.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 db/migrate/20150911064528_alter_user_activities.rb diff --git a/db/migrate/20150911064528_alter_user_activities.rb b/db/migrate/20150911064528_alter_user_activities.rb new file mode 100644 index 000000000..a65f933d8 --- /dev/null +++ b/db/migrate/20150911064528_alter_user_activities.rb @@ -0,0 +1,26 @@ +class AlterUserActivities < ActiveRecord::Migration + def up + count = UserActivity.all.count / 30 + 3 + transaction do + for i in 1 ... count do i + UserActivity.page(i).per(30).each do |activity| + if activity.act_type == 'Message' + if activity.act + unless activity.act.parent_id.nil? + parent_act = UserActivity.where("act_id = #{activity.act.parent.id} and act_type='Message'").first + parent_act.created_at = activity.act.parent.children.maximum("created_on") + parent_act.save + activity.destroy + end + else + activity.destroy + end + end + end + end + end + end + + def down + end +end From 86f0889f5b09b1ea8555f51602b87823d7bca532 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 11 Sep 2015 16:53:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?"=E6=88=91=E7=9A=84=E5=8A=A8=E6=80=81"?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E7=9A=84?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6669a43d7..5db53b07b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -863,7 +863,7 @@ class UsersController < ApplicationController when "project_message" @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('created_at desc').limit(10).offset(@page * 10) when "current_user" - @user_activities = UserActivity.where("user_id = #{User.current.id} and ((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}))").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("user_id = #{@user.id} and ((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}))").order('created_at desc').limit(10).offset(@page * 10) else @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})").order('created_at desc').limit(10).offset(@page * 10) end