-
Notifications
You must be signed in to change notification settings - Fork 10
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
+48
−20
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Central source of course block dates for the LMS. | ||
""" | ||
|
||
__version__ = '2.5.0' | ||
__version__ = '2.5.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from django.contrib import auth | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from edx_django_utils.cache.utils import TieredCache | ||
from edx_django_utils.cache.utils import RequestCache, TieredCache | ||
from opaque_keys.edx.locator import CourseLocator | ||
|
||
from edx_when import api, models | ||
|
@@ -54,8 +54,11 @@ def setUp(self): | |
relative_dates_patcher = patch('edx_when.api._are_relative_dates_enabled', return_value=True) | ||
relative_dates_patcher.start() | ||
self.addCleanup(relative_dates_patcher.stop) | ||
self.addCleanup(TieredCache.dangerous_clear_all_tiers) | ||
self.addCleanup(self._clear_caches) | ||
|
||
@staticmethod | ||
def _clear_caches(): | ||
RequestCache.clear_all_namespaces() | ||
TieredCache.dangerous_clear_all_tiers() | ||
|
||
@patch('edx_when.api.Schedule', DummySchedule) | ||
|
@@ -274,7 +277,7 @@ def test_set_user_override(self, initial_date, override_date, expected_date): | |
api.set_dates_for_course(str(block_id.course_key), items) | ||
|
||
api.set_date_for_block(block_id.course_key, block_id, 'due', override_date, user=self.user) | ||
TieredCache.dangerous_clear_all_tiers() | ||
self._clear_caches() | ||
retrieved = api.get_dates_for_course(block_id.course_key, user=self.user.id) | ||
assert len(retrieved) == NUM_OVERRIDES | ||
assert retrieved[block_id, 'due'] == expected_date | ||
|
@@ -308,7 +311,7 @@ def test_set_date_for_block(self, initial_date, override_date, expected_date): | |
|
||
api.set_dates_for_course(str(block_id.course_key), items) | ||
api.set_date_for_block(block_id.course_key, block_id, 'due', override_date) | ||
TieredCache.dangerous_clear_all_tiers() | ||
self._clear_caches() | ||
retrieved = api.get_dates_for_course(block_id.course_key, user=self.user.id) | ||
assert len(retrieved) == NUM_OVERRIDES | ||
assert retrieved[block_id, 'due'] == expected_date | ||
|
@@ -329,13 +332,13 @@ def test_remove_user_override(self, initial_date, override_date, expected_date): | |
api.set_dates_for_course(str(block_id.course_key), items) | ||
|
||
api.set_date_for_block(block_id.course_key, block_id, 'due', override_date, user=self.user) | ||
TieredCache.dangerous_clear_all_tiers() | ||
self._clear_caches() | ||
retrieved = api.get_dates_for_course(block_id.course_key, user=self.user.id) | ||
assert len(retrieved) == NUM_OVERRIDES | ||
assert retrieved[block_id, 'due'] == expected_date | ||
|
||
api.set_date_for_block(block_id.course_key, block_id, 'due', None, user=self.user) | ||
TieredCache.dangerous_clear_all_tiers() | ||
self._clear_caches() | ||
retrieved = api.get_dates_for_course(block_id.course_key, user=self.user.id) | ||
assert len(retrieved) == NUM_OVERRIDES | ||
if isinstance(initial_date, timedelta): | ||
|
@@ -484,7 +487,7 @@ def test_relative_date_past_cutoff_date(self): | |
] | ||
assert api.get_dates_for_course(course_key, schedule=self.schedule) == dict(dates) | ||
|
||
TieredCache.dangerous_clear_all_tiers() | ||
self._clear_caches() | ||
|
||
# Now set schedule start date too close to the end date and verify that we no longer get due dates | ||
self.schedule.created = datetime(2019, 4, 15) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
with self.assertNumQueries(0 if schedule else 1): | ||
# Second time, the request cache eliminates all querying... | ||
with self.assertNumQueries(0): | ||
cached_dates = api.get_dates_for_course( | ||
course_id=self.course.id, user=user, schedule=schedule | ||
) | ||
assert dates == cached_dates | ||
|
||
# Now wipe all cache tiers... | ||
TieredCache.dangerous_clear_all_tiers() | ||
self._clear_caches() | ||
|
||
# No cached values - so will do *all* queries again. | ||
with self.assertNumQueries(query_count): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.