Skip to content

Commit

Permalink
Reduce sql queries when rendering inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 11, 2017
1 parent b858805 commit aec6517
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def index

@total = scope.count

@inbox_notification = current_user.notifications.inbox.count

@notifications = scope.newest.page(page).per(per_page)
@cur_selected = [per_page, @total].min
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/notifications/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= link_to root_path(per_page: params[:per_page]) do %>
<%= octicon 'inbox', height: 16, class: 'sidebar-icon text-primary' %>
Inbox
<span class="label label-muted"><%= @inbox_notification %></span>
<span class="label label-muted"><%= @unread_notifications.sum(&:last) %></span>
<% end %>
</li>
<li role="presentation" class="<%= 'active' if params[:archive].present? %>">
Expand Down
6 changes: 3 additions & 3 deletions app/views/notifications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="flex-container">
<div class="panel panel-default panel-notifications">
<div class="panel-heading">
<% if @notifications.any? %>
<% if @notifications.to_a.any? %>
<div class="btn-group pull-right hidden-xs" data-toggle="tooltip" data-placement="left" title="Notifications per page">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<% if params[:per_page].present? %>
Expand All @@ -31,7 +31,7 @@
<button type="button" class="hidden-md hidden-lg btn btn-default" data-toggle="offcanvas">
<%= octicon 'three-bars', :height => 16 %>
</button>
<% if @notifications.any? %>
<% if @notifications.to_a.any? %>
<label class="btn btn-default select-all" for="select_all">
<input id="select_all" type="checkbox" class='js-select_all'>
</label>
Expand All @@ -46,7 +46,7 @@
<%= render 'filter-list' %>
</div>

<% if @notifications.any? %>
<% if @notifications.to_a.any? %>
<table class='table table-hover table-notifications js-table-notifications' data-refresh-interval=<%= current_user.effective_refresh_interval %>>
<%= render partial: 'notification', collection: @notifications %>
</table>
Expand Down

0 comments on commit aec6517

Please sign in to comment.