个人主页申请类消息优化,性能提升1s多,查询时间22ms
This commit is contained in:
parent
9734c46b2f
commit
11c5b0ab41
|
@ -2242,18 +2242,13 @@ class UsersController < ApplicationController
|
|||
# 待审批的申请
|
||||
# 待审批的消息一般不多,可以特殊处理
|
||||
def unapproval_applied_list
|
||||
@message_alls = []
|
||||
messages_all = MessageAll.where(:user_id => @user.id, :message_type => ["AppliedMessage", "CourseMessage", "ForgeMessage"]).includes(:message).where("message.status =?", 0).order("created_at desc")
|
||||
messages_all.each do |message_all|
|
||||
mess = message_all.message
|
||||
if message_all.message_type == "CourseMessage" && mess && mess.try(:course_message_type) == "JoinCourseRequest" && mess.try(:status) == 0
|
||||
@message_alls << mess
|
||||
elsif message_all.message_type == "AppliedMessage" && mess && mess.try(:status) == 0 && (["Organization", "AppliedContest", "StudentWorksScoresAppeal", "AppliedProject", "ApplyAddSchools"].include? mess.try(:applied_type))
|
||||
@message_alls << mess
|
||||
elsif message_all.message_type == "ForgeMessage" && message_all.message && message_all.message.try(:forge_message_type) == "PullRequest" && (message_all.message.try(:status) == 1 || message_all.message.try(:status) == 3)
|
||||
@message_alls << mess
|
||||
end
|
||||
end
|
||||
user_id = User.current.id
|
||||
sql = "SELECT * FROM `message_alls` ma left join `forge_messages` fm on ma.message_id=fm.id
|
||||
left join `course_messages` cm on ma.message_id=cm.id left join `applied_messages` apm on ma.message_id=apm.id
|
||||
where (ma.user_id =#{user_id} and ma.message_type = 'ForgeMessage' and fm.forge_message_type='PullRequest' and fm.status=0 and fm.user_id=#{user_id} ) or
|
||||
(ma.user_id=#{user_id} and ma.message_type='AppliedMessage' and apm.applied_type in ('Organization', 'AppliedContest', 'StudentWorksScoresAppeal', 'AppliedProject', 'ApplyAddSchools') and apm.user_id =#{user_id} and apm.status =0 ) or
|
||||
(ma.user_id=#{user_id} and ma.message_type='CourseMessage' and cm.course_message_type='JoinCourseRequest' and cm.status=0 and cm.user_id=#{user_id} );"
|
||||
@message_alls = MessageAll.find_by_sql(sql)
|
||||
@message_count = @message_alls.count
|
||||
@message_alls = paginateHelper @message_alls, 20
|
||||
respond_to do |format|
|
||||
|
|
Loading…
Reference in New Issue