Move fetching of services to controller to avoid n+1 queries

This commit is contained in:
Karina Kwiatek 2023-01-28 21:42:25 +01:00
parent 4dcc5dea55
commit 3e2b65d7b8
2 changed files with 12 additions and 9 deletions

View File

@ -8,16 +8,12 @@ class InboxController < ApplicationController
def show
find_author
find_inbox_entries
if @author_user && @inbox_count.zero?
# rubocop disabled because of a false positive
flash[:info] = t(".author.info", author: @author) # rubocop:disable Rails/ActionControllerFlashBeforeRender
redirect_to inbox_path(last_id: params[:last_id])
end
check_for_empty_filter
@delete_id = find_delete_id
@services = current_user.services
@disabled = true if @inbox.empty?
respond_to do |format|
format.html
format.turbo_stream do
@ -50,6 +46,13 @@ class InboxController < ApplicationController
private
def check_for_empty_filter
return unless @author_user && @inbox_count.zero?
flash[:info] = t(".author.info", author: @author)
redirect_to inbox_path(last_id: params[:last_id])
end
def find_author
return if params[:author].blank?

View File

@ -40,9 +40,9 @@
= render "shared/format_link"
.card-footer.d-none{ id: "ib-options-#{i.id}" }
%h4= t(".sharing.heading")
- if current_user.services.count.positive?
- if @services.count.positive?
.row
- current_user.services.each do |service|
- @services.each do |service|
.col-md-3.col-sm-4.col-xs-6
%label
%input{ type: "checkbox", name: "ib-share", checked: :checked, data: { ib_id: i.id, service: service.provider } }