Skip to content
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

Conversation

ChrisChV
Copy link
Contributor

@ChrisChV ChrisChV commented Oct 28, 2024

Description

Fix:

Fixed component counter synchronization in these cases:

  1. When deleting a component inside a collection.
  2. With the library published, when adding a new component in a collection and reverting library changes.
  3. 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.

Supporting information

Related github issues:

Testing instructions

  • Run make requirements on lms and cms shell.
  1. When deleting a component inside a collection
  • Go the library home of a library
  • Go to the collection list page.
  • Create a component in a collection or use a collection with components.
  • Delete a component on the collection home page.
  • Return to the collection list page and verify the component count in the collection card
  1. With the library published, when adding a new component in a collection and reverting library changes.
  • Go the library home of a published library
  • Go to the collection list page.
  • Create a component in a collection on the collection home page.
  • Return to the collection list page and verify the component count in the collection card.
  • Discarg library changes
  • Return to the collection list page and verify the component count in the collection card.
  1. With the library published, when deleting a component inside a collection and reverting library changes.
  • Go the library home of a published library
  • Go to the collection list page.
  • Create a component in a collection (and publish) or use a collection with components published.
  • Delete a component on the collection home page
  • Return to the collection list page and verify the component count in the collection card.
  • Discarg library changes
  • Return to the collection list page and verify the component count in the collection card.

To test the new published > num_counts field, you can follow the testing instructions in: openedx/frontend-app-authoring#1481

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 28, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 28, 2024

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If 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 @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@ChrisChV ChrisChV marked this pull request as draft October 28, 2024 23:47
@ChrisChV ChrisChV marked this pull request as ready for review October 29, 2024 19:34
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Oct 29, 2024
@ChrisChV ChrisChV changed the title fix: "num components" not updated when a component in a collection is discarded fix: "num components" not updated when a component in a collection is discarded [FC-0062] Oct 30, 2024
Copy link
Contributor

@DanielVZ96 DanielVZ96 left a 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.

openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
@ChrisChV ChrisChV changed the title fix: "num components" not updated when a component in a collection is discarded [FC-0062] fix: Keep sync component count in collection card [FC-0062] Nov 7, 2024
Comment on lines 489 to 500
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
Copy link
Contributor

Choose a reason for hiding this comment

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

@ChrisChV CC @ormsbee

If a collection contains 200 items, will this result in 400 queries? I think we need a way to just get this as

Suggested change
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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

event_receiver.call_args_list[1].kwargs,
)

def test_delete_component_and_revert(self):
Copy link
Contributor

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 !

Copy link
Contributor

@pomegranited pomegranited left a 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 issues N/A
  • Includes documentation N/A
  • User-facing strings are extracted for translation N/A

Copy link
Contributor

@ormsbee ormsbee left a 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.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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):
Copy link
Contributor

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".)

Copy link
Contributor Author

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

Copy link
Contributor

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
Copy link
Contributor

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.

# 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
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

@ChrisChV ChrisChV Nov 14, 2024

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 👍

Copy link
Contributor Author

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

@ChrisChV
Copy link
Contributor Author

Hi @ormsbee, this is ready for another review

@ChrisChV ChrisChV requested a review from ormsbee November 18, 2024 18:58
Copy link
Contributor

@ormsbee ormsbee left a 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.
@ChrisChV ChrisChV force-pushed the chris/FAL-3921-remove-unpublished-collections branch from dce18dc to b372142 Compare November 19, 2024 20:16
@ChrisChV
Copy link
Contributor Author

@ormsbee Done 👍

@ormsbee ormsbee merged commit d5850c8 into openedx:master Nov 19, 2024
51 checks passed
@ChrisChV ChrisChV deleted the chris/FAL-3921-remove-unpublished-collections branch November 19, 2024 20:51
ChrisChV added a commit to open-craft/edx-platform that referenced this pull request Nov 19, 2024
)

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.
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

bradenmacdonald pushed a commit that referenced this pull request Nov 21, 2024
…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]>
@itsjeyd itsjeyd removed the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Nov 28, 2024
@feanil feanil mentioned this pull request Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants