Merge branch 'develop' into 'develop'

message 的delay job发送方式优化



See merge request !77
This commit is contained in:
黄井泉 2016-12-19 10:27:45 +08:00
commit 38659fc5a9
2 changed files with 18 additions and 8 deletions

View File

@ -328,17 +328,27 @@ 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
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
def contain_messages_message vs
CourseMessage.create(vs)
end
#更新用户分数 -by zjc

View File

@ -50,7 +50,7 @@
</li>
<li class="c_grey">
<% if !activity.assigned_to_id.nil? && activity.assigned_to_id != 0 %>
<% if activity.try(:assigned_to).try(:realname).empty? %>
<% if activity.try(:assigned_to).try(:realname).blank? %>
<%= link_to activity.assigned_to, user_path(activity.assigned_to_id)%>
<% else %>
<%= link_to activity.try(:assigned_to).try(:realname), user_path(activity.assigned_to_id)%>