系统消息查询/显示优化(减150ms)

This commit is contained in:
huang 2017-01-12 17:14:52 +08:00
parent d5a0133b0b
commit 4be495a7b0
3 changed files with 26 additions and 24 deletions

View File

@ -1990,11 +1990,12 @@ end
end
def show
if is_current_user
if User.current == @user
# 系统消息总显示在最前面,显示周期30天
@system_messages = SystemMessage.where("created_at > ?", Time.now - 86400 * 30)
# 自己的主页显示消息
# 系统消息为管理员发送,我的消息中包含有系统消息
@message_alls = []
@system_messages
messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" , @user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
messages.each do |message_all|

View File

@ -1,9 +1,7 @@
<% message_alls.each do |ma| %>
<%# 系统消息 %>
<% if ma.class == SystemMessage && many_days_ago(ma.created_at, 30) %>
<%= render :partial => 'users/user_message_system', :locals => {:ma => ma} %>
<% end %>
<%# 系统消息总显示在最上面 %>
<%= render :partial => 'users/user_message_system' %>
<% message_alls.each do |ma| %>
<% if ma.class == AtMessage && ma.at_valid? && ma.at_message %>
<%= render :partial => 'users/user_at_message', :locals => {:ma => ma} %>
<% end %>
@ -36,7 +34,7 @@
<% if ma.class == OrgMessage %>
<%= render :partial => 'users/user_message_org', :locals => {:ma => ma} %>
<% end %>
<%# 申请类消息 %>
<% if ma.class == AppliedMessage %>
<%= render :partial => 'users/user_message_applied', :locals => {:ma => ma} %>

View File

@ -1,16 +1,19 @@
<ul class="homepageNewsList fl">
<div class="longMessageWidth">
<li class="homepageNewsPortrait fl">
<div class="navHomepageLogo fl"><%= image_tag("/images/trustie_logo1.png", width: "30px", height: "30px", class: "mt3") %></div>
</li>
<li class="homepageNewsPubType fl">
<span style="color: red;float: left">系统消息:</span>
</li>
<li class="messageInformationContents">
<%= link_to ma.subject.blank? ? (ma.content.nil? ? ma.description.html_safe : ma.content.html_safe) : ma.subject, user_system_messages_path(User.current, :anchor => "position_#{ma.id}"),
:id => "content_link_#{ma.id}", :target => '_blank' %>
</li>
</div>
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% @system_messages.each do |ma| %>
<ul class="homepageNewsList fl">
<div class="longMessageWidth">
<li class="homepageNewsPortrait fl">
<div class="navHomepageLogo fl"><%= image_tag("/images/trustie_logo1.png", width: "30px", height: "30px", class: "mt3") %></div>
</li>
<li class="homepageNewsPubType fl">
<span style="color: red;float: left">系统消息:</span>
</li>
<li class="messageInformationContents">
<%= link_to ma.subject.blank? ? (ma.content.nil? ? ma.description.html_safe : ma.content.html_safe) : ma.subject, user_system_messages_path(User.current, :anchor => "position_#{ma.id}"),
:id => "content_link_#{ma.id}", :target => '_blank' %>
</li>
</div>
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>