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

refactor: reduce duplicate workflow update calls #2129

Merged
merged 15 commits into from
Jan 22, 2024

Conversation

nsprenkle
Copy link
Contributor

@nsprenkle nsprenkle commented Dec 1, 2023

TL;DR - Reduce the number of duplicate workflow updates from common ORA data load patterns.

What changed?

Asking for a workflow from the WorkflowAPI called get_workflow_info which would update the workflow before fetching workflow information. Since many of the other fields on WorkflowAPI referenced that workflow property, asking for any of this information would cause additional refreshes of the workflow, needlessly.

Loading the ORA MFE, I was averaging over 20 workflow refreshes and a local load time of ~500ms.

This PR begins to add a few refactors aimed at reducing how frequently we call a workflow update to (ideally) once per user action, calling cached workflow info any time between those actions.

  • Memoize workflow property on WorkflowAPI to return last-fetched workflow data instead of re-updating/fetching.
  • Load workflow on WorkflowAPI init (e.g. XBlock / MFE load)
  • Reduce the number of times WorkflowAPI is initialized by memoizing workflow_data on OpenassessmentBlock and ORADataAccessor on fetch / update.
  • Attempt to re-fetch workflow when a workflow is not present (this is not ideal from a performance standpoint but appears to fix a large number of tests).

Other changes:

  • Remove unused grades accessor from WorkflowAPI.
  • Updated some mocking to fix tests which relied on old call structure.
  • Fixed a handful of typos I encountered along the way.

NOTE that this does mean it is more possible to get stale workflows so it is up to each endpoint / caller to determine if they need to refresh the workflow state on a per-action basis.

Developer Checklist

Testing Instructions

  • Unit testing
  • Smoke test suites

Reviewer Checklist

Collectively, these should be completed by reviewers of this PR:

  • I've done a visual code review
  • I've tested the new functionality

FYI: @openedx/content-aurora

@nsprenkle nsprenkle changed the title refactor: /reduce duplicate workflow update calls refactor: reduce duplicate workflow update calls Dec 5, 2023
@nsprenkle nsprenkle force-pushed the nsprenkle/reduce-duplicate-update-calls branch from 69aede9 to 9499741 Compare December 14, 2023 17:53
@nsprenkle nsprenkle force-pushed the nsprenkle/reduce-duplicate-update-calls branch 3 times, most recently from 5f2005c to 36b0b77 Compare January 8, 2024 22:35
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0c02eb0) 94.95% compared to head (f800d6f) 94.95%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2129   +/-   ##
=======================================
  Coverage   94.95%   94.95%           
=======================================
  Files         191      191           
  Lines       20608    20618   +10     
  Branches     1863     1867    +4     
=======================================
+ Hits        19568    19578   +10     
  Misses        777      777           
  Partials      263      263           
Flag Coverage Δ
unittests 94.95% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nsprenkle nsprenkle marked this pull request as ready for review January 11, 2024 16:43
@nsprenkle nsprenkle requested a review from a team as a code owner January 11, 2024 16:43
@nsprenkle nsprenkle force-pushed the nsprenkle/reduce-duplicate-update-calls branch 2 times, most recently from 8635c6e to 96f905b Compare January 11, 2024 18:32
Copy link
Contributor

@mattcarter mattcarter left a comment

Choose a reason for hiding this comment

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

approved

Copy link
Contributor

@leangseu-edx leangseu-edx left a comment

Choose a reason for hiding this comment

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

Update version bump. The rest look good.

Copy link
Contributor

@jansenk jansenk left a comment

Choose a reason for hiding this comment

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

great job

@nsprenkle nsprenkle force-pushed the nsprenkle/reduce-duplicate-update-calls branch from 96f905b to 112c8ee Compare January 12, 2024 18:45
Previously, anything that requested a workflow would cause a workflow
update and refresh. This changes that logic to:
1. Only init workflow API once through load of ORA block (reloaded each
time the page / ORA MFE load).
2. On load, update workflow.
3. Calls for workflow info reference cached workflow.
4. Try to update workflow when none found.

Note we can still  manually refresh workflow info with either
get_workflow_info or update_workflow_status.
Within the new MFE calls, we need to consistently leverage the API version of workflow calls to take advantage of the cached workflow state.
@nsprenkle nsprenkle force-pushed the nsprenkle/reduce-duplicate-update-calls branch from 112c8ee to 969ae6e Compare January 16, 2024 20:53
@nsprenkle nsprenkle merged commit c29b7f3 into master Jan 22, 2024
9 checks passed
@nsprenkle nsprenkle deleted the nsprenkle/reduce-duplicate-update-calls branch January 22, 2024 18:17
BryanttV pushed a commit to eduNEXT/edx-ora2 that referenced this pull request Feb 6, 2024
* feat: remove duplicate workflow lookups

Previously, anything that requested a workflow would cause a workflow
update and refresh. This changes that logic to:
1. Only init workflow API once through load of ORA block (reloaded each
time the page / ORA MFE load).
2. On load, update workflow.
3. Calls for workflow info reference cached workflow.
4. Try to update workflow when none found.

Note we can still  manually refresh workflow info with either
get_workflow_info or update_workflow_status.

* refactor: call the API version of get_workflow_info

Within the new MFE calls, we need to consistently leverage the API version of workflow calls to take advantage of the cached workflow state.

* docs: typo fixes and docstring updates

* feat: remove no-longer-needed function_trace

* fix: cache workflow on update_workflow_status

* fix: remove unnecessary update in tests

* style: more consistent return statements

* test: refactor mocking to fix tests

* chore: bump ORA to 6.0.28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants