讨论区发帖delay 模式优化

This commit is contained in:
huang 2016-12-19 10:24:36 +08:00
parent 9a6a4a5203
commit cb33bec7db
1 changed files with 17 additions and 7 deletions

View File

@ -328,19 +328,29 @@ class Message < ActiveRecord::Base
def delay_message_send
if self.course
if self.parent_id.nil? # 发帖
self.delay.contain_messages_message
dm = []
self.course.members.includes(:user).each do |m|
if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息
dm << {course_message_type:'Message',course_message_id:self.id, :user_id => m.user_id,
:course_id => self.board.course_id, :viewed => false}
if dm.size >= 30
self.delay.contain_messages_message(dm)
dm.clear
end
unless dm.empty?
self.delay.contain_messages_message(dm)
end
end
end
def contain_messages_message
self.course.members.includes(:user).each do |m|
if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
end
end
end
def contain_messages_message vs
CourseMessage.create(vs)
end
#更新用户分数 -by zjc
def be_user_score
#新建message且无parent的为发帖