Merge pull request #1014 from Retrospring/fix/inbox-services-query
Move fetching of services to controller to avoid n+1 queries
This commit is contained in:
commit
4dc5a65f74
|
@ -5,7 +5,7 @@ class InboxController < ApplicationController
|
|||
|
||||
after_action :mark_inbox_entries_as_read, only: %i[show]
|
||||
|
||||
def show
|
||||
def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
||||
find_author
|
||||
find_inbox_entries
|
||||
|
||||
|
@ -13,15 +13,17 @@ class InboxController < ApplicationController
|
|||
# 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])
|
||||
return
|
||||
end
|
||||
|
||||
@delete_id = find_delete_id
|
||||
|
||||
@disabled = true if @inbox.empty?
|
||||
services = current_user.services
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.html { render "show", locals: { services: } }
|
||||
format.turbo_stream do
|
||||
render "show", layout: false, status: :see_other
|
||||
render "show", locals: { services: }, layout: false, status: :see_other
|
||||
|
||||
# rubocop disabled as just flipping a flag doesn't need to have validations to be run
|
||||
@inbox.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
|
||||
|
|
|
@ -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 } }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#entries
|
||||
- @inbox.each do |i|
|
||||
= render "inbox/entry", i:
|
||||
= render "inbox/entry", services:, i:
|
||||
|
||||
- if @inbox.empty?
|
||||
%p.empty= t(".empty")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
= turbo_stream.append "entries" do
|
||||
- @inbox.each do |i|
|
||||
= render "inbox/entry", i:
|
||||
= render "inbox/entry", services:, i:
|
||||
|
||||
= turbo_stream.update "paginator" do
|
||||
- if @more_data_available
|
||||
|
|
|
@ -179,9 +179,7 @@ describe InboxController, type: :controller do
|
|||
inbox: [],
|
||||
inbox_last_id: nil,
|
||||
more_data_available: false,
|
||||
inbox_count: 0,
|
||||
delete_id: "ib-delete-all",
|
||||
disabled: true
|
||||
inbox_count: 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -213,9 +211,7 @@ describe InboxController, type: :controller do
|
|||
inbox: [],
|
||||
inbox_last_id: nil,
|
||||
more_data_available: false,
|
||||
inbox_count: 0,
|
||||
delete_id: "ib-delete-all",
|
||||
disabled: true
|
||||
inbox_count: 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue