From 6ef7a15a5b29583cdcbe718b0dcdc4588cf8bcca Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 18 Dec 2016 12:28:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8F=AA=E8=AF=BB?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E6=94=BE=E5=88=B0delayed=5Fjob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index b7e4b9efd..e70cae5bb 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -33,12 +33,16 @@ class HomeworkCommonController < ApplicationController @homeworks = paginateHelper @homework_commons,10 #设置at已读 - @homeworks.each do |homework| - # homework.journals_for_messages.each do |j| - # User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} - # end - homework.delay.set_jour_viewed + ids = @homeworks.inject([]) do |ids, homework| + jids = homework.journals_for_messages.map(&:id) + jids ? ids + jids : ids + + # homework.delay.set_jour_viewed end + User.current.at_messages.where(viewed: false, + at_message_type: 'JournalsForMessage', + at_message_id: ids).update_all(viewed: true) + @left_nav_type = 3 respond_to do |format| format.js From d7155afbe51f22e6662acfc6ad84c6c400e767fa Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 18 Dec 2016 18:17:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=87=E5=88=86=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3delayed=5Fjob=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/news.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/models/news.rb b/app/models/news.rb index f39352c94..d57565dd3 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -208,16 +208,25 @@ class News < ActiveRecord::Base def delay_news_send if self.course - self.delay.contain_news_message + + vs = [] + self.course.members.each do | m| + if m.user_id != self.author_id + vs << {course_message_type:'News',course_message_id:self.id, :user_id => m.user_id, + :course_id => self.course_id, :viewed => false} + + if vs.size >= 30 + self.delay.contain_news_message(vs) + vs.clear + end + end + end + end end - def contain_news_message - self.course.members.each do |m| - if m.user_id != self.author_id - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - end - end + def contain_news_message(vs) + CourseMessage.create(vs) end # Time 2015-03-31 13:50:54 From d34ed4b744838da0f1f17ad76d0738c199f64c9f Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 18 Dec 2016 18:25:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=87=E5=88=86=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3delayed=5Fjob=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/news.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/news.rb b/app/models/news.rb index d57565dd3..c436724fd 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -222,6 +222,10 @@ class News < ActiveRecord::Base end end + unless vs.empty? + self.delay.contain_news_message(vs) + end + end end From 34f845088574e05bbffb07603b7bd7af0cafc791 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 18 Dec 2016 18:29:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?ids=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index e70cae5bb..5e2e7c48a 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -39,9 +39,11 @@ class HomeworkCommonController < ApplicationController # homework.delay.set_jour_viewed end - User.current.at_messages.where(viewed: false, + unless ids.empty? + User.current.at_messages.where(viewed: false, at_message_type: 'JournalsForMessage', at_message_id: ids).update_all(viewed: true) + end @left_nav_type = 3 respond_to do |format|