Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions cms/djangoapps/contentstore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from config_models.models import ConfigurationModel
from django.db import models
from django.db.models import Count, F, Q, QuerySet
from django.db.models import Count, F, Q, QuerySet, Max
from django.db.models.fields import IntegerField, TextField
from django.db.models.functions import Coalesce
from django.db.models.lookups import GreaterThan
Expand Down Expand Up @@ -160,7 +160,8 @@ def filter_links(
ready_to_sync = link_filter.pop('ready_to_sync', None)
result = cls.objects.filter(**link_filter).select_related(
"upstream_block__publishable_entity__published__version",
"upstream_block__publishable_entity__learning_package"
"upstream_block__publishable_entity__learning_package",
"upstream_block__publishable_entity__published__publish_log_record__publish_log",
).annotate(
ready_to_sync=(
GreaterThan(
Expand All @@ -186,13 +187,15 @@ def summarize_by_downstream_context(cls, downstream_context_key: CourseKey) -> Q
"upstream_context_title": "CS problems 3",
"upstream_context_key": "lib:OpenedX:CSPROB3",
"ready_to_sync_count": 11,
"total_count": 14
"total_count": 14,
"last_published_at": "2025-05-02T20:20:44.989042Z"
},
{
"upstream_context_title": "CS problems 2",
"upstream_context_key": "lib:OpenedX:CSPROB2",
"ready_to_sync_count": 15,
"total_count": 24
"total_count": 24,
"last_published_at": "2025-05-03T21:20:44.989042Z"
},
]
"""
Expand All @@ -201,7 +204,10 @@ def summarize_by_downstream_context(cls, downstream_context_key: CourseKey) -> Q
upstream_context_title=F("upstream_block__publishable_entity__learning_package__title"),
).annotate(
ready_to_sync_count=Count("id", Q(ready_to_sync=True)),
total_count=Count('id')
total_count=Count("id"),
last_published_at=Max(
"upstream_block__publishable_entity__published__publish_log_record__publish_log__published_at"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradenmacdonald @ormsbee Is there a better way to get the published date for an upstream component here?

@bradenmacdonald bradenmacdonald May 8, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm aware of. Though I think you could do a much more efficient query to just check when the particular upstream learning context (library) was last published, without caring about whether or not that publish involved components used in upstream-downstream links.

)
)
return result

Expand Down Expand Up @@ -307,6 +313,7 @@ def filter_links(
result = cls.objects.filter(**link_filter).select_related(
"upstream_container__publishable_entity__published__version",
"upstream_container__publishable_entity__learning_package"
"upstream_container__publishable_entity__published__publish_log_record__publish_log",
).annotate(
ready_to_sync=(
GreaterThan(
Expand All @@ -332,13 +339,15 @@ def summarize_by_downstream_context(cls, downstream_context_key: CourseKey) -> Q
"upstream_context_title": "CS problems 3",
"upstream_context_key": "lib:OpenedX:CSPROB3",
"ready_to_sync_count": 11,
"total_count": 14
"total_count": 14,
"last_published_at": "2025-05-02T20:20:44.989042Z"
},
{
"upstream_context_title": "CS problems 2",
"upstream_context_key": "lib:OpenedX:CSPROB2",
"ready_to_sync_count": 15,
"total_count": 24
"total_count": 24,
"last_published_at": "2025-05-03T21:20:44.989042Z"
},
]
"""
Expand All @@ -347,7 +356,10 @@ def summarize_by_downstream_context(cls, downstream_context_key: CourseKey) -> Q
upstream_context_title=F("upstream_container__publishable_entity__learning_package__title"),
).annotate(
ready_to_sync_count=Count("id", Q(ready_to_sync=True)),
total_count=Count('id')
total_count=Count('id'),
last_published_at=Max(
"upstream_container__publishable_entity__published__publish_log_record__publish_log__published_at"
)
)
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ class PublishableEntityLinksSummarySerializer(serializers.Serializer):
upstream_context_key = serializers.CharField(read_only=True)
ready_to_sync_count = serializers.IntegerField(read_only=True)
total_count = serializers.IntegerField(read_only=True)
last_published_at = serializers.DateTimeField(read_only=True)
4 changes: 3 additions & 1 deletion cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ def get(self, request: _AuthenticatedRequest, course_key_string: str):
"upstream_context_key": "lib:OpenedX:CSPROB3",
"ready_to_sync_count": 11,
"total_count": 14
"last_published_at": "2025-05-02T20:20:44.989042Z"
},
{
"upstream_context_title": "CS problems 2",
"upstream_context_key": "lib:OpenedX:CSPROB2",
"ready_to_sync_count": 15,
"total_count": 24
"total_count": 24,
"last_published_at": "2025-05-03T21:20:44.989042Z"
},
]
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def setUp(self):
self.learner = UserFactory(username="learner", password="password")
self._set_library_block_olx(self.html_lib_id, "<html><b>Hello world!</b></html>")
self._publish_library_block(self.html_lib_id)
self._publish_library_block(self.video_lib_id)
self._publish_library_block(self.html_lib_id)

def _api(self, method, url, data, expect_response):
"""
Expand Down Expand Up @@ -546,6 +548,7 @@ def test_200_summary(self):
'upstream_context_key': self.library_id,
'ready_to_sync_count': 0,
'total_count': 3,
'last_published_at': self.now.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
}]
self.assertListEqual(data, expected)
response = self.call_api(str(self.course.id))
Expand All @@ -556,5 +559,6 @@ def test_200_summary(self):
'upstream_context_key': self.library_id,
'ready_to_sync_count': 1,
'total_count': 2,
'last_published_at': self.now.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
}]
self.assertListEqual(data, expected)