-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert mime_type field to its own model. (#129)
This commit normalizes the Media/MIME type in RawContent to be a foreign key to a new table rather than a text string. This was done for a couple of reasons: 1. Recent problems with edx-platform's courseware_studentmodule table have driven home the point that we should try to reduce index sizes where possible, and RawContent is likely to grow into a very large table in time. 2. Media type designations can sometimes change, and that's much easier to do as a data migration if it's in its own lookup table, rather than affecting millions of rows in RawContent. In order to support these changes, I've also added LRU caching for MediaType lookup... which in turn required a test helper that will clear out the values between test calls. That's the rationale behind our new openedx_learning.lib.test_utils.TestCase.
- Loading branch information
Showing
16 changed files
with
255 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
Open edX Learning ("Learning Core"). | ||
""" | ||
__version__ = "0.3.7" | ||
__version__ = "0.4.0" |
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Test-friendly helpers for caching. | ||
LRU caching can be especially helpful for Learning Core data models because so | ||
much of it is immutable, e.g. Media Type lookups. But while these data models | ||
are immutable within a given site, we also want to be able to track and clear | ||
these caches across test runs. Later on, we may also want to inspect them to | ||
make sure they are not growing overly large. | ||
""" | ||
import functools | ||
|
||
# List of functions that have our | ||
_lru_cached_fns = [] | ||
|
||
|
||
def lru_cache(*args, **kwargs): | ||
""" | ||
Thin wrapper over functools.lru_cache that lets us clear all caches later. | ||
""" | ||
def decorator(fn): | ||
wrapped_fn = functools.lru_cache(*args, **kwargs)(fn) | ||
_lru_cached_fns.append(wrapped_fn) | ||
return wrapped_fn | ||
return decorator | ||
|
||
|
||
def clear_lru_caches(): | ||
""" | ||
Clear all LRU caches that use our lru_cache decorator. | ||
Useful for tests. | ||
""" | ||
for fn in _lru_cached_fns: | ||
fn.cache_clear() |
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
Oops, something went wrong.