Skip to content

Commit

Permalink
Revert server side ordering to fix performance issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Nov 21, 2022
1 parent 511865a commit 23021fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
[this.channelFilter]: true,
page: this.$route.query.page || 1,
exclude: this.currentChannelId,
ordering: this.channelFilter === 'public' ? 'name' : '-modified',
}).then(page => {
this.pageCount = page.total_pages;
this.channels = page.results;
Expand Down
17 changes: 6 additions & 11 deletions contentcuration/contentcuration/viewsets/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ class ChannelViewSet(ValuesViewset):
serializer_class = ChannelSerializer
pagination_class = ChannelListPagination
filterset_class = ChannelFilter
ordering_fields = ["modified", "name"]
ordering = "-modified"

field_map = channel_field_map
values = base_channel_values + ("edit", "view", "unpublished_changes")
Expand All @@ -414,15 +412,6 @@ def get_queryset(self):
queryset = super(ChannelViewSet, self).get_queryset()
user_id = not self.request.user.is_anonymous and self.request.user.id
user_queryset = User.objects.filter(id=user_id)
# Add the last modified node modified value as the channel last modified
channel_main_tree_nodes = ContentNode.objects.filter(
tree_id=OuterRef("main_tree__tree_id")
)
queryset = queryset.annotate(
modified=Subquery(
channel_main_tree_nodes.values("modified").order_by("-modified")[:1]
)
)

return queryset.annotate(
edit=Exists(user_queryset.filter(editable_channels=OuterRef("id"))),
Expand All @@ -445,6 +434,12 @@ def annotate_queryset(self, queryset):
queryset = queryset.annotate(
count=SQCount(non_topic_content_ids, field="content_id"),
)
# Add the last modified node modified value as the channel last modified
queryset = queryset.annotate(
modified=Subquery(
channel_main_tree_nodes.values("modified").order_by("-modified")[:1]
)
)

queryset = queryset.annotate(unpublished_changes=Exists(_unpublished_changes_query(OuterRef("id"))))

Expand Down

0 comments on commit 23021fb

Please sign in to comment.