Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
3b528f44
Unverified
Commit
3b528f44
authored
5 years ago
by
adeelehsan
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #21950 from edx/aehsan/prod-735/logged_improverd_cache_miss_hit
Logged improved for cache
parents
aa25b4a3
c2600c44
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/core/djangoapps/catalog/tests/test_utils.py
+19
-16
19 additions, 16 deletions
openedx/core/djangoapps/catalog/tests/test_utils.py
openedx/core/djangoapps/catalog/utils.py
+8
-3
8 additions, 3 deletions
openedx/core/djangoapps/catalog/utils.py
with
27 additions
and
19 deletions
openedx/core/djangoapps/catalog/tests/test_utils.py
+
19
−
16
View file @
3b528f44
...
@@ -57,6 +57,7 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import Cou
...
@@ -57,6 +57,7 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import Cou
from
openedx.core.djangoapps.site_configuration.tests.factories
import
SiteFactory
from
openedx.core.djangoapps.site_configuration.tests.factories
import
SiteFactory
from
openedx.core.djangolib.testing.utils
import
CacheIsolationTestCase
,
skip_unless_lms
from
openedx.core.djangolib.testing.utils
import
CacheIsolationTestCase
,
skip_unless_lms
from
student.tests.factories
import
CourseEnrollmentFactory
,
UserFactory
from
student.tests.factories
import
CourseEnrollmentFactory
,
UserFactory
from
openedx.core.djangoapps.site_configuration.tests.test_util
import
with_site_configuration_context
UTILS_MODULE
=
'
openedx.core.djangoapps.catalog.utils
'
UTILS_MODULE
=
'
openedx.core.djangoapps.catalog.utils
'
User
=
get_user_model
()
# pylint: disable=invalid-name
User
=
get_user_model
()
# pylint: disable=invalid-name
...
@@ -83,11 +84,12 @@ class TestGetPrograms(CacheIsolationTestCase):
...
@@ -83,11 +84,12 @@ class TestGetPrograms(CacheIsolationTestCase):
# When called before UUIDs are cached, the function should return an
# When called before UUIDs are cached, the function should return an
# empty list and log a warning.
# empty list and log a warning.
self
.
assertEqual
(
get_programs
(
site
=
self
.
site
),
[])
with
with_site_configuration_context
(
domain
=
self
.
site
.
name
,
configuration
=
{
'
COURSE_CATALOG_API_URL
'
:
'
foo
'
}):
mock_warning
.
assert_called_once_with
(
self
.
assertEqual
(
get_programs
(
site
=
self
.
site
),
[])
u
'
Failed to get program UUIDs from the cache for site {}.
'
.
format
(
self
.
site
.
domain
)
mock_warning
.
assert_called_once_with
(
)
u
'
Failed to get program UUIDs from the cache for site {}.
'
.
format
(
self
.
site
.
domain
)
mock_warning
.
reset_mock
()
)
mock_warning
.
reset_mock
()
# Cache UUIDs for all 3 programs.
# Cache UUIDs for all 3 programs.
cache
.
set
(
cache
.
set
(
...
@@ -158,21 +160,22 @@ class TestGetPrograms(CacheIsolationTestCase):
...
@@ -158,21 +160,22 @@ class TestGetPrograms(CacheIsolationTestCase):
mock_cache
.
get
.
return_value
=
[
program
[
'
uuid
'
]
for
program
in
programs
]
mock_cache
.
get
.
return_value
=
[
program
[
'
uuid
'
]
for
program
in
programs
]
mock_cache
.
get_many
.
side_effect
=
fake_get_many
mock_cache
.
get_many
.
side_effect
=
fake_get_many
actual_programs
=
get_programs
(
site
=
self
.
site
)
with
with_site_configuration_context
(
domain
=
self
.
site
.
name
,
configuration
=
{
'
COURSE_CATALOG_API_URL
'
:
'
foo
'
}):
actual_programs
=
get_programs
(
site
=
self
.
site
)
# All 3 cached programs should be returned. An info message should be
# All 3 cached programs should be returned. An info message should be
# logged about the one that was initially missing, but the code should
# logged about the one that was initially missing, but the code should
# be able to stitch together all the details.
# be able to stitch together all the details.
self
.
assertEqual
(
self
.
assertEqual
(
set
(
program
[
'
uuid
'
]
for
program
in
actual_programs
),
set
(
program
[
'
uuid
'
]
for
program
in
actual_programs
),
set
(
program
[
'
uuid
'
]
for
program
in
all_programs
.
values
())
set
(
program
[
'
uuid
'
]
for
program
in
all_programs
.
values
())
)
)
self
.
assertFalse
(
mock_warning
.
called
)
self
.
assertFalse
(
mock_warning
.
called
)
mock_info
.
assert_called_with
(
'
Failed to get details for 1 programs. Retrying.
'
)
mock_info
.
assert_called_with
(
'
Failed to get details for 1 programs. Retrying.
'
)
for
program
in
actual_programs
:
for
program
in
actual_programs
:
key
=
PROGRAM_CACHE_KEY_TPL
.
format
(
uuid
=
program
[
'
uuid
'
])
key
=
PROGRAM_CACHE_KEY_TPL
.
format
(
uuid
=
program
[
'
uuid
'
])
self
.
assertEqual
(
program
,
all_programs
[
key
])
self
.
assertEqual
(
program
,
all_programs
[
key
])
def
test_get_one
(
self
,
mock_warning
,
_mock_info
):
def
test_get_one
(
self
,
mock_warning
,
_mock_info
):
expected_program
=
ProgramFactory
()
expected_program
=
ProgramFactory
()
...
...
This diff is collapsed.
Click to expand it.
openedx/core/djangoapps/catalog/utils.py
+
8
−
3
View file @
3b528f44
...
@@ -119,9 +119,14 @@ def get_programs(site=None, uuid=None, uuids=None, course=None, organization=Non
...
@@ -119,9 +119,14 @@ def get_programs(site=None, uuid=None, uuids=None, course=None, organization=Non
# without programs. After this is changed, log any cache misses here.
# without programs. After this is changed, log any cache misses here.
return
[]
return
[]
elif
site
:
elif
site
:
uuids
=
cache
.
get
(
SITE_PROGRAM_UUIDS_CACHE_KEY_TPL
.
format
(
domain
=
site
.
domain
),
[])
site_config
=
getattr
(
site
,
'
configuration
'
,
None
)
if
not
uuids
:
catalog_url
=
site_config
.
get_value
(
'
COURSE_CATALOG_API_URL
'
)
if
site_config
else
None
logger
.
warning
(
u
'
Failed to get program UUIDs from the cache for site {}.
'
.
format
(
site
.
domain
))
if
site_config
and
catalog_url
:
uuids
=
cache
.
get
(
SITE_PROGRAM_UUIDS_CACHE_KEY_TPL
.
format
(
domain
=
site
.
domain
),
[])
if
not
uuids
:
logger
.
warning
(
u
'
Failed to get program UUIDs from the cache for site {}.
'
.
format
(
site
.
domain
))
else
:
uuids
=
[]
elif
organization
:
elif
organization
:
uuids
=
get_programs_for_organization
(
organization
)
uuids
=
get_programs_for_organization
(
organization
)
if
not
uuids
:
if
not
uuids
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment