From 28cfbf2ef53db62a87510b39dcb9392ce63cd129 Mon Sep 17 00:00:00 2001 From: Corry Haines Date: Tue, 10 Jan 2023 16:16:54 -0800 Subject: [PATCH] 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. --- api/views/timelines.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/views/timelines.py b/api/views/timelines.py index 01767d9..973ccb2 100644 --- a/api/views/timelines.py +++ b/api/views/timelines.py @@ -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,