From 07da35c17c4ff8e0fc7b90aba0b619dae119a633 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 28 Nov 2019 04:08:00 +0100 Subject: [PATCH] Fix n+1 query for bookmarks on statuses (#12494) --- app/presenters/status_relationships_presenter.rb | 3 ++- app/serializers/rest/status_serializer.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/presenters/status_relationships_presenter.rb b/app/presenters/status_relationships_presenter.rb index 64e688d878..3cc905a75e 100644 --- a/app/presenters/status_relationships_presenter.rb +++ b/app/presenters/status_relationships_presenter.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? diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index 08bc4d82a0..1ed8948da1 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -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