FIX: Load categories with user activity and drafts (#26553)

When lazy load categories is enabled, categories should be loaded with
user activity items and drafts because the categories may not be
preloaded on the client side.
This commit is contained in:
Bianca Nenciu
2024-04-10 17:35:42 +03:00
committed by GitHub
parent 3733db866c
commit 8ce836c039
12 changed files with 80 additions and 9 deletions

View File

@ -17,7 +17,15 @@ class DraftsController < ApplicationController
limit: fetch_limit_from_params(default: nil, max: INDEX_LIMIT),
)
render json: { drafts: stream ? serialize_data(stream, DraftSerializer) : [] }
response = { drafts: serialize_data(stream, DraftSerializer) }
if guardian.can_lazy_load_categories?
category_ids = stream.map { |draft| draft.topic&.category_id }.compact.uniq
categories = Category.secured(guardian).with_parents(category_ids)
response[:categories] = serialize_data(categories, CategoryBadgeSerializer)
end
render json: response
end
def show