-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Keep sync component count in collection card [FC-0062] #35734
fix: Keep sync component count in collection card [FC-0062] #35734
Conversation
Thanks for the pull request, @ChrisChV! What's next?Please work through the following steps to get your changes ready for engineering review: 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Let us know that your PR is ready for review:Who will review my changes?This repository is currently maintained by Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:
When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM just a small suggestion to make the comment easier to understand.
- I tested this: (describe what you tested)
- I read through the code
- I checked for accessibility issues
- Includes documentation
- I made sure any change in configuration variables is reflected in the corresponding client's
configuration-secure
repository.
draf_num_children = 0 | ||
published_num_children = 0 | ||
|
||
# Count draft and published children | ||
for entity in collection.entities.all(): | ||
draft = authoring_api.get_draft_version(entity.id) | ||
published = authoring_api.get_published_version(entity.id) | ||
|
||
if draft: | ||
draf_num_children += 1 | ||
if published: | ||
published_num_children += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a collection contains 200 items, will this result in 400 queries? I think we need a way to just get this as
draf_num_children = 0 | |
published_num_children = 0 | |
# Count draft and published children | |
for entity in collection.entities.all(): | |
draft = authoring_api.get_draft_version(entity.id) | |
published = authoring_api.get_published_version(entity.id) | |
if draft: | |
draf_num_children += 1 | |
if published: | |
published_num_children += 1 | |
draft_num_children = collection.entities.filter(has_draft).count() | |
published_num_children =collection.entities.filter(has_published).count() |
Is that filter
possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That filter is definitely possible, but we might want to split it out a bit to give the publishing API control over translating from PublishableEntities -> Drafts... Something like
draft_num_children = get_drafts(collection.entities.all()).count()
Where get_drafts
is implemented in the publishing
app. So ostensibly anything can throw in its qset of PublishableEntities and get Drafts without collections
needing to know how that mapping really works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated b6f2d98, using openedx/openedx-learning#257
event_receiver.call_args_list[1].kwargs, | ||
) | ||
|
||
def test_delete_component_and_revert(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for testing this case too @ChrisChV !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Works perfectly, thank you for dealing with all these edge cases @ChrisChV !
- I tested this using (very complete) the PR test instructions
- I read through the code
-
I checked for accessibility issuesN/A -
Includes documentationN/A -
User-facing strings are extracted for translationN/A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some longer term observations, but the only blocking thing is to please change the pinned dependency references to not use the GitHub repo urls.
requirements/edx/development.txt
Outdated
@@ -1381,7 +1381,7 @@ openedx-filters==1.11.0 | |||
# -r requirements/edx/testing.txt | |||
# lti-consumer-xblock | |||
# ora2 | |||
openedx-learning==0.17.0 | |||
openedx-learning @ git+https://github.com/open-craft/openedx-learning.git@chris/FAL-3921-get-drafts-and-get-published |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that openedx-learning has been updated in PyPI, please remove the direct git references here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, updated here: f9ef3f9
# | ||
# This is to update component counts in all library collections, | ||
# because there may be components that have been discarded in the revert. | ||
for collection in authoring_api.get_collections(learning_package.id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to block this PR over this, but I don't think re-indexing every Collection in the Library is an acceptable long term solution. A Library might have many, many Collections. One of the deep problems with Modulestore has been the tendency for apps to have to reprocess the entire course because they don't have granular data on whether the pieces that are relevant to them have changed or not. I don't want that pattern to get started here.
The reset_drafts_to_published
function can be modified to return a queryset of Drafts
or PublishableEntities
or something along those lines, and we can allow this code to figure out which collections were actually updated. (Side note: The reset_drafts_to_published
is also pretty inefficient because I was only thinking about the manual editing use case and not really thinking about importing potentially thousands of components at once and then hitting "discard changes".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this, could this be done in a follow-up task? @bradenmacdonald @pomegranited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as long as the bug is fixed now and the fix is backported to Sumac, we can address those refactors and improvements in a follow-up task. Let's do that as soon as sumac.0 is cut. Doing it now will complicate other backports like this one, especially if any change to openedx-learning are required.
But I don't want to postpone it any later than that, or we won't get to it. Ideally you can start on the PRs for it now, even if we don't merge until after Sumac.0 is released.
@@ -1318,6 +1341,39 @@ def revert_changes(library_key): | |||
) | |||
) | |||
|
|||
# For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[off-topic] Out of scope, but also wanted to note that revert_changes
might not be the best name for this function. It's described as "Discard Changes" in the UI, and it means specifically to reset the draft version to be the published version for all content. The word "revert" might be more appropriate to use when you have something that was already published, and you want to undo that publish. That's definitely a more product question though.
requirements/common_constraints.txt
Outdated
# event-tracking 2.4.1 upgrades to pymongo 4.4.0 which is not supported on edx-platform. | ||
# We will pin event-tracking to do not break existing installations | ||
# This can be unpinned once https://github.com/openedx/edx-platform/issues/34586 | ||
# has been resolved and edx-platform is running with pymongo>=4.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this pulled in accidentally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was introduced in f9ef3f9. I ran make compile-requirements
in the cms shell. The command generates those changes automatically. Is this something unexpected? I have re-run the command on this branch and master
and I get the same result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I always remove any changes like that from the diff before committing, if it's unrelated to the PR in question. Keep things focused on one set of changes. Those dependencies will be updated in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense, I will do that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bradenmacdonald @ormsbee It's already updated here 040ff12
Hi @ormsbee, this is ready for another review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisChV: Please squash your commits and add context from the PR description into the commit message. I'll merge this in the morning EST.
Fixed component counter synchronization in these cases: * When deleting a component inside a collection. * With the library published, when adding a new component in a collection and reverting library changes. * With the library published, when deleting a component inside a collection and reverting library changes. Also adds a published > num_counts field in collections in the search index.
dce18dc
to
b372142
Compare
@ormsbee Done 👍 |
) Fixed component counter synchronization in these cases: * When deleting a component inside a collection. * With the library published, when adding a new component in a collection and reverting library changes. * With the library published, when deleting a component inside a collection and reverting library changes. Also adds a published > num_counts field in collections in the search index.
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
1 similar comment
2U Release Notice: This PR has been deployed to the edX production environment. |
…5734) (#35886) * fix: keep library collection card component count in sync (#35734) Fixed component counter synchronization in these cases: * When deleting a component inside a collection. * With the library published, when adding a new component in a collection and reverting library changes. * With the library published, when deleting a component inside a collection and reverting library changes. Also adds a published > num_counts field in collections in the search index. * fix: remove learner_downloadable field references from libraries (#35788) Also bumps openedx-learning to v0.17.0, which no longer has this field. * chore: Update common_contraints.txt --------- Co-authored-by: Cristhian Garcia <[email protected]>
Description
Fix:
Fixed component counter synchronization in these cases:
Also adds a
published > num_counts
field in collections in the search index.Supporting information
Related github issues:
Internal link: https://tasks.opencraft.com/browse/FAL-3921
Depends on: Add
filter_publishable_entities
to publishing API [FC-0062] openedx-learning#257Testing instructions
make requirements
on lms and cms shell.To test the new
published > num_counts
field, you can follow the testing instructions in: openedx/frontend-app-authoring#1481