From 98d533e8f9df96ea7889f2013467b76ba87b6d7b Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sat, 29 Aug 2015 15:34:18 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=95=B4=E7=90=86=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=202=E3=80=81=E4=B8=AA=E4=BA=BA=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E6=B7=BB=E5=8A=A0=E4=B8=8E=E6=9B=B4=E6=96=B0=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_activity.rb | 4 +-- app/models/forge_activity.rb | 4 +-- ...0810064247_add_created_at_to_activities.rb | 2 +- .../20150811010817_update_activities_data.rb | 28 ++++++++--------- .../20150811065543_add_course_activities.rb | 10 +++++++ .../20150811080754_course_activities.rb | 2 +- ...50814031258_update_course_activity_time.rb | 8 +++-- .../20150820022416_create_user_activity.rb | 9 +----- .../20150820025358_about_user_activities.rb | 30 +++++++++---------- db/schema.rb | 1 - 10 files changed, 52 insertions(+), 46 deletions(-) diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 1d0920c1c..284687870 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -10,7 +10,7 @@ class CourseActivity < ActiveRecord::Base #在个人动态里面增加当前动态 def add_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first + user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'").first if user_activity user_activity.save else @@ -24,7 +24,7 @@ class CourseActivity < ActiveRecord::Base end def destroy_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'") + user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'") user_activity.destroy_all end end diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index b7fc5e4c2..9bc10bebf 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -25,7 +25,7 @@ class ForgeActivity < ActiveRecord::Base #在个人动态里面增加当前动态 def add_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first + user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'").first if user_activity user_activity.save else @@ -39,7 +39,7 @@ class ForgeActivity < ActiveRecord::Base end def destroy_user_activity - user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'") + user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'") user_activity.destroy_all end end diff --git a/db/migrate/20150810064247_add_created_at_to_activities.rb b/db/migrate/20150810064247_add_created_at_to_activities.rb index 864ed82d6..e2f35441f 100644 --- a/db/migrate/20150810064247_add_created_at_to_activities.rb +++ b/db/migrate/20150810064247_add_created_at_to_activities.rb @@ -3,6 +3,6 @@ class AddCreatedAtToActivities < ActiveRecord::Migration add_column :activities, :created_at, :timestamp end def end - remove_column :activities, :created_at + remove_column :activities, :created_at end end diff --git a/db/migrate/20150811010817_update_activities_data.rb b/db/migrate/20150811010817_update_activities_data.rb index 7ed19a607..374407cd3 100644 --- a/db/migrate/20150811010817_update_activities_data.rb +++ b/db/migrate/20150811010817_update_activities_data.rb @@ -1,19 +1,19 @@ class UpdateActivitiesData < ActiveRecord::Migration def up - count = Activity.all.count / 20 + 1 - transaction do - for i in 1 ... count do i - Activity.page(i).per(20).each do |activity| - type = activity.act_type - if type=='Contest' || type=='Message' || type=='News'|| type=='Journal'|| type=='Issue'|| type=='Principal'||type=='JournalsForMessage' - activity.created_at = activity.act.created_on if activity.act - elsif type=='Contestnotification' || type=='HomeworkCommon' || type=='Poll' - activity.created_at = activity.act.created_at if activity.act - end - activity.save - end - end - end + # count = Activity.all.count / 20 + 1 + # transaction do + # for i in 1 ... count do i + # Activity.page(i).per(20).each do |activity| + # type = activity.act_type + # if type=='Contest' || type=='Message' || type=='News'|| type=='Journal'|| type=='Issue'|| type=='Principal'||type=='JournalsForMessage' + # activity.created_at = activity.act.created_on if activity.act + # elsif type=='Contestnotification' || type=='HomeworkCommon' || type=='Poll' + # activity.created_at = activity.act.created_at if activity.act + # end + # activity.save + # end + # end + # end end def down diff --git a/db/migrate/20150811065543_add_course_activities.rb b/db/migrate/20150811065543_add_course_activities.rb index 03ec7e354..86b96bd44 100644 --- a/db/migrate/20150811065543_add_course_activities.rb +++ b/db/migrate/20150811065543_add_course_activities.rb @@ -1,5 +1,14 @@ class AddCourseActivities < ActiveRecord::Migration def up + create_table :user_activities do |t| + t.string :act_type + t.integer :act_id + t.string :container_type + t.integer :container_id + + t.timestamps + end + create_table :course_activities do |t| t.integer :user_id t.integer :course_id @@ -11,5 +20,6 @@ class AddCourseActivities < ActiveRecord::Migration def down drop_table :course_activities + drop_table :user_activities end end diff --git a/db/migrate/20150811080754_course_activities.rb b/db/migrate/20150811080754_course_activities.rb index a4cae915d..910cb4520 100644 --- a/db/migrate/20150811080754_course_activities.rb +++ b/db/migrate/20150811080754_course_activities.rb @@ -35,6 +35,6 @@ class CourseActivities < ActiveRecord::Migration end def down - CourseActivity.destroy_all + # CourseActivity.destroy_all end end diff --git a/db/migrate/20150814031258_update_course_activity_time.rb b/db/migrate/20150814031258_update_course_activity_time.rb index 155e212a3..26d0dc4bc 100644 --- a/db/migrate/20150814031258_update_course_activity_time.rb +++ b/db/migrate/20150814031258_update_course_activity_time.rb @@ -1,9 +1,9 @@ class UpdateCourseActivityTime < ActiveRecord::Migration def up - count = CourseActivity.all.count / 10 + 1 + count = CourseActivity.all.count / 30 + 1 transaction do for i in 1 ... count do i - CourseActivity.page(i).per(10).each do |activity| + CourseActivity.page(i).per(30).each do |activity| if activity.course_act if activity.course_act.respond_to?("created_at") activity.created_at = activity.course_act.created_at @@ -11,6 +11,10 @@ class UpdateCourseActivityTime < ActiveRecord::Migration activity.created_at = activity.course_act.created_on end activity.save + + user_activity = UserActivity.where("act_type = '#{activity.course_act_type.to_s}' and act_id = '#{activity.course_act_id}'").first + user_activity.created_at = activity.created_at + user_activity.save end end end diff --git a/db/migrate/20150820022416_create_user_activity.rb b/db/migrate/20150820022416_create_user_activity.rb index 7d6a978d1..0ff64b1f3 100644 --- a/db/migrate/20150820022416_create_user_activity.rb +++ b/db/migrate/20150820022416_create_user_activity.rb @@ -1,16 +1,9 @@ class CreateUserActivity < ActiveRecord::Migration def up - create_table :user_activities do |t| - t.string :act_type - t.integer :act_id - t.string :container_type - t.integer :container_id - t.timestamps - end end def down - drop_table :user_activities + end end diff --git a/db/migrate/20150820025358_about_user_activities.rb b/db/migrate/20150820025358_about_user_activities.rb index 82b58a537..e02b4711f 100644 --- a/db/migrate/20150820025358_about_user_activities.rb +++ b/db/migrate/20150820025358_about_user_activities.rb @@ -15,23 +15,23 @@ class AboutUserActivities < ActiveRecord::Migration end end - course_count = CourseActivity.all.count / 30 + 2 - transaction do - for i in 1 ... course_count do i - CourseActivity.page(i).per(30).each do |activity| - user_activity = UserActivity.new - user_activity.act_id = activity.course_act_id - user_activity.act_type = activity.course_act_type - user_activity.container_type = "Course" - user_activity.container_id = activity.course_id - user_activity.created_at = activity.created_at - user_activity.save - end - end - end + # course_count = CourseActivity.all.count / 30 + 2 + # transaction do + # for i in 1 ... course_count do i + # CourseActivity.page(i).per(30).each do |activity| + # user_activity = UserActivity.new + # user_activity.act_id = activity.course_act_id + # user_activity.act_type = activity.course_act_type + # user_activity.container_type = "Course" + # user_activity.container_id = activity.course_id + # user_activity.created_at = activity.created_at + # user_activity.save + # end + # end + # end end def down - UserActivity.destroy_all + # UserActivity.destroy_all end end diff --git a/db/schema.rb b/db/schema.rb index 5b09c8f3d..3c43292e5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -913,7 +913,6 @@ ActiveRecord::Schema.define(:version => 20150826061843) do t.datetime "created_on" t.integer "comments_count", :default => 0, :null => false t.integer "course_id" - t.datetime "updated_on" end add_index "news", ["author_id"], :name => "index_news_on_author_id"