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

perf: request cache get_schedule_for_user #259

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

ormsbee
Copy link
Contributor

@ormsbee ormsbee commented Jul 13, 2024

Calls to render a Unit were calling this function many times, even when
schedules are not enabled. This was leading to noticeable performance
issues in production, particularly for Units with many components.

I still need to test this properly, which is probably going to involve
hacky looking mocking because of the weird model relationship this has
with edx-platform (where it's actually importing the Schedule model
from edx-platform).

@ormsbee
Copy link
Contributor Author

ormsbee commented Jul 13, 2024

@ormsbee
Copy link
Contributor Author

ormsbee commented Jul 13, 2024

Note to self: test failures are probably because we need to clear the request cache between tests.

@@ -526,16 +529,15 @@ def test_get_dates_for_course_query_counts(self, has_schedule, pass_user_object,
course_id=self.course.id, user=user, schedule=schedule
)

# Second time, the request cache eliminates all querying (sometimes)...
# If a schedule is not provided, we will get the schedule to avoid caching outdated dates
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'm not sure if it's dangerous that I'm altering this particular behavior, i.e. if there's something that assumes schedules are never cached.

@ormsbee
Copy link
Contributor Author

ormsbee commented Jul 13, 2024

@ilee2u, @zacharis278, @MichaelRoytman: Would one of you have time to review this? It was reported as a performance issue on the forum. I imagine edx.org would also seeing the same issue.

(The failing check at the moment is codecov rate limiting.)

Copy link
Member

@rijuma rijuma left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ilee2u ilee2u left a comment

Choose a reason for hiding this comment

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

Looks good on my end 🚀

@ormsbee ormsbee added the performance Relates to improving latency/throughput or reducing resource usage label Aug 5, 2024
ormsbee added 2 commits August 5, 2024 18:37
Calls to render a Unit were calling this function many times, even when
schedules are not enabled. This was leading to noticeable performance
issues in production, particularly for Units with many components.
Comment on lines +21 to +22
if not Schedule:
return None
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 is not covered by any tests at this moment, because it never happens in practice–either we're running inside the edx-platform process and the import succeeds, or we're in edx-when tests and it's been mocked with a DummySchedule object.

@ilee2u: I'm inclined to just ignore this omission (no test existed for the similar check it replaced), but I can add a test for this if you think it's warranted.

@ormsbee
Copy link
Contributor Author

ormsbee commented Aug 5, 2024

Hi folks. I'm back from PTO and looking to get this landed.

I rebased just to change the update date for the version bump in the CHANGELOG.rst. The unit test error is there because of codecov rate limiting. In the previous run where that test did run, the one thing it flagged was this issue.

@ilee2u: I do have access to override the checks in this case, but I'll defer to your judgement as to what's appropriate here. I'll try re-running the test late tonight to see if it goes through okay.

Thank you.

@ormsbee ormsbee merged commit 5739fb5 into openedx:master Aug 12, 2024
9 of 10 checks passed
@ormsbee ormsbee deleted the cache-schedule branch August 12, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Relates to improving latency/throughput or reducing resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants