Fix n+1 query for bookmarks on statuses (#12494)

master
Eugen Rochko 5 years ago committed by GitHub
parent d9793b2367
commit 07da35c17c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/presenters/status_relationships_presenter.rb
  2. 4
      app/serializers/rest/status_serializer.rb

@ -1,7 +1,8 @@
# frozen_string_literal: true
class StatusRelationshipsPresenter
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map,
:bookmarks_map
def initialize(statuses, current_account_id = nil, **options)
if current_account_id.nil?

@ -95,8 +95,8 @@ class REST::StatusSerializer < ActiveModel::Serializer
end
def bookmarked
if instance_options && instance_options[:bookmarks]
instance_options[:bookmarks].bookmarks_map[object.id] || false
if instance_options && instance_options[:relationships]
instance_options[:relationships].bookmarks_map[object.id] || false
else
current_user.account.bookmarked?(object)
end

Loading…
Cancel
Save