From 68338c46e12be5e5622b1531e4d7f38355c7273b Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 17 Sep 2015 15:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=8A=A8=E6=80=81=E6=8C=89?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/comments_controller.rb | 3 ++ app/controllers/issues_controller.rb | 3 ++ app/controllers/messages_controller.rb | 3 ++ app/controllers/users_controller.rb | 18 ++++---- ...071652_update_user_activities_update_at.rb | 16 +++++++ db/schema.rb | 43 ++++++++----------- 6 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 db/migrate/20150917071652_update_user_activities_update_at.rb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 4088d4156..6b421bf2a 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -49,6 +49,9 @@ class CommentsController < ApplicationController # end # # ������ض�̬�ļ�¼add end flash[:notice] = l(:label_comment_added) + user_activity = UserActivity.where("act_type='News' and act_id =#{@news.id}").first + user_activity.updated_at = @comment.created_on + user_activity.save end if params[:user_activity_id] diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 47e425710..bf854abe8 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -394,6 +394,9 @@ class IssuesController < ApplicationController jour.notes = params[:notes] jour.journalized = @issue jour.save + user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first + user_activity.updated_at = jour.created_on + user_activity.save @user_activity_id = params[:user_activity_id] respond_to do |format| format.js diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 9b0fd56a0..aae33e52a 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -161,6 +161,9 @@ class MessagesController < ApplicationController @reply.content = @quote + @reply.content @reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] @topic.children << @reply + user_activity = UserActivity.where("act_type='Message' and act_id =#{@topic.id}").first + user_activity.updated_at = @reply.created_on + user_activity.save #@topic.update_attribute(:updated_on, Time.now) if !@reply.new_record? if params[:asset_id] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4796d0c0c..91518eaca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -853,24 +853,24 @@ class UsersController < ApplicationController if params[:type].present? case params[:type] when "course_homework" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) when "course_news" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) when "course_message" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) when "course_poll" - @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) when "project_issue" - @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) 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) + @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) when "current_user" - @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) + @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('updated_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) + @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('updated_at desc').limit(10).offset(@page * 10) end 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) + @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('updated_at desc').limit(10).offset(@page * 10) end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] diff --git a/db/migrate/20150917071652_update_user_activities_update_at.rb b/db/migrate/20150917071652_update_user_activities_update_at.rb new file mode 100644 index 000000000..7fbd425f4 --- /dev/null +++ b/db/migrate/20150917071652_update_user_activities_update_at.rb @@ -0,0 +1,16 @@ +class UpdateUserActivitiesUpdateAt < ActiveRecord::Migration + def up + count = UserActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + UserActivity.page(i).per(30).each do |activity| + activity.updated_at = activity.created_at + activity.save + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index b696765f8..a3c8277bb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150911064528) do +ActiveRecord::Schema.define(:version => 20150917071652) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -476,13 +476,6 @@ ActiveRecord::Schema.define(:version => 20150911064528) do add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" - create_table "discuss_demos", :force => true do |t| - t.string "title" - t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "documents", :force => true do |t| t.integer "project_id", :default => 0, :null => false t.integer "category_id", :default => 0, :null => false @@ -497,26 +490,23 @@ ActiveRecord::Schema.define(:version => 20150911064528) do add_index "documents", ["created_on"], :name => "index_documents_on_created_on" add_index "documents", ["project_id"], :name => "documents_project_id" - create_table "dts", :primary_key => "Num", :force => true do |t| - t.string "Defect", :limit => 50 - t.string "Category", :limit => 50 - t.string "File" - t.string "Method" - t.string "Module", :limit => 20 - t.string "Variable", :limit => 50 - t.integer "StartLine" - t.integer "IPLine" - t.string "IPLineCode", :limit => 200 - t.string "Judge", :limit => 15 - t.integer "Review", :limit => 1 + create_table "dts", :force => true do |t| + t.string "IPLineCode" t.string "Description" - t.text "PreConditions", :limit => 2147483647 - t.text "TraceInfo", :limit => 2147483647 - t.text "Code", :limit => 2147483647 + t.string "Num" + t.string "Variable" + t.string "TraceInfo" + t.string "Method" + t.string "File" + t.string "IPLine" + t.string "Review" + t.string "Category" + t.string "Defect" + t.string "PreConditions" + t.string "StartLine" t.integer "project_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "enabled_modules", :force => true do |t| @@ -916,6 +906,7 @@ ActiveRecord::Schema.define(:version => 20150911064528) 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"