Improve performance on /api/v1/timelines/home (#387)

Prefetch/select required fields for API version of home. Requires considerably more data than HTML version of home.
This commit is contained in:
Corry Haines 2023-01-10 16:16:54 -08:00 committed by GitHub
parent 150cd9503d
commit 28cfbf2ef5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,19 @@ def home(
# Grab a paginated result set of instances
paginator = MastodonPaginator()
queryset = TimelineService(request.identity).home()
queryset = queryset.select_related(
"subject_post_interaction__post",
"subject_post_interaction__post__author",
"subject_post_interaction__post__author__domain",
)
queryset = queryset.prefetch_related(
"subject_post__mentions__domain",
"subject_post_interaction__post__attachments",
"subject_post_interaction__post__mentions",
"subject_post_interaction__post__emojis",
"subject_post_interaction__post__mentions__domain",
"subject_post_interaction__post__author__posts",
)
pager = paginator.paginate_home(
queryset,
min_id=min_id,