Merge pull request #13069 from edx/christina/cache-disable-state
Use request cache for disabled_xblock_types
This commit is contained in:
@@ -229,18 +229,18 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase):
|
||||
# # of sql queries to default,
|
||||
# # of mongo queries,
|
||||
# )
|
||||
('no_overrides', 1, True, False): (34, 6),
|
||||
('no_overrides', 2, True, False): (40, 6),
|
||||
('no_overrides', 3, True, False): (50, 6),
|
||||
('ccx', 1, True, False): (34, 6),
|
||||
('ccx', 2, True, False): (40, 6),
|
||||
('ccx', 3, True, False): (50, 6),
|
||||
('no_overrides', 1, False, False): (34, 6),
|
||||
('no_overrides', 2, False, False): (40, 6),
|
||||
('no_overrides', 3, False, False): (50, 6),
|
||||
('ccx', 1, False, False): (34, 6),
|
||||
('ccx', 2, False, False): (40, 6),
|
||||
('ccx', 3, False, False): (50, 6),
|
||||
('no_overrides', 1, True, False): (35, 6),
|
||||
('no_overrides', 2, True, False): (41, 6),
|
||||
('no_overrides', 3, True, False): (51, 6),
|
||||
('ccx', 1, True, False): (35, 6),
|
||||
('ccx', 2, True, False): (41, 6),
|
||||
('ccx', 3, True, False): (51, 6),
|
||||
('no_overrides', 1, False, False): (35, 6),
|
||||
('no_overrides', 2, False, False): (41, 6),
|
||||
('no_overrides', 3, False, False): (51, 6),
|
||||
('ccx', 1, False, False): (35, 6),
|
||||
('ccx', 2, False, False): (41, 6),
|
||||
('ccx', 3, False, False): (51, 6),
|
||||
}
|
||||
|
||||
|
||||
@@ -252,19 +252,19 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase):
|
||||
__test__ = True
|
||||
|
||||
TEST_DATA = {
|
||||
('no_overrides', 1, True, False): (34, 3),
|
||||
('no_overrides', 2, True, False): (40, 3),
|
||||
('no_overrides', 3, True, False): (50, 3),
|
||||
('ccx', 1, True, False): (34, 3),
|
||||
('ccx', 2, True, False): (40, 3),
|
||||
('ccx', 3, True, False): (50, 3),
|
||||
('ccx', 1, True, True): (35, 3),
|
||||
('ccx', 2, True, True): (41, 3),
|
||||
('ccx', 3, True, True): (51, 3),
|
||||
('no_overrides', 1, False, False): (34, 3),
|
||||
('no_overrides', 2, False, False): (40, 3),
|
||||
('no_overrides', 3, False, False): (50, 3),
|
||||
('ccx', 1, False, False): (34, 3),
|
||||
('ccx', 2, False, False): (40, 3),
|
||||
('ccx', 3, False, False): (50, 3),
|
||||
('no_overrides', 1, True, False): (35, 3),
|
||||
('no_overrides', 2, True, False): (41, 3),
|
||||
('no_overrides', 3, True, False): (51, 3),
|
||||
('ccx', 1, True, False): (35, 3),
|
||||
('ccx', 2, True, False): (41, 3),
|
||||
('ccx', 3, True, False): (51, 3),
|
||||
('ccx', 1, True, True): (36, 3),
|
||||
('ccx', 2, True, True): (42, 3),
|
||||
('ccx', 3, True, True): (52, 3),
|
||||
('no_overrides', 1, False, False): (35, 3),
|
||||
('no_overrides', 2, False, False): (41, 3),
|
||||
('no_overrides', 3, False, False): (51, 3),
|
||||
('ccx', 1, False, False): (35, 3),
|
||||
('ccx', 2, False, False): (41, 3),
|
||||
('ccx', 3, False, False): (51, 3),
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ class SelfPacedCourseInfoTestCase(LoginEnrollmentTestCase, SharedModuleStoreTest
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
def test_num_queries_instructor_paced(self):
|
||||
self.fetch_course_info_with_queries(self.instructor_paced_course, 22, 4)
|
||||
self.fetch_course_info_with_queries(self.instructor_paced_course, 23, 4)
|
||||
|
||||
def test_num_queries_self_paced(self):
|
||||
self.fetch_course_info_with_queries(self.self_paced_course, 22, 4)
|
||||
self.fetch_course_info_with_queries(self.self_paced_course, 23, 4)
|
||||
|
||||
@@ -293,7 +293,9 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest
|
||||
"""
|
||||
test entrance exam score. we will hit the method get_entrance_exam_score to verify exam score.
|
||||
"""
|
||||
with self.assertNumQueries(1):
|
||||
# One query is for getting the list of disabled XBlocks (which is
|
||||
# then stored in the request).
|
||||
with self.assertNumQueries(2):
|
||||
exam_score = get_entrance_exam_score(self.request, self.course)
|
||||
self.assertEqual(exam_score, 0)
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ from mock import MagicMock, patch, Mock
|
||||
from opaque_keys.edx.keys import UsageKey, CourseKey
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from pyquery import PyQuery
|
||||
from courseware.module_render import hash_resource
|
||||
from xblock.field_data import FieldData
|
||||
from xblock.runtime import Runtime
|
||||
from xblock.fields import ScopeIds
|
||||
@@ -2225,9 +2224,7 @@ class TestDisabledXBlockTypes(ModuleStoreTestCase):
|
||||
# pylint: disable=no-member
|
||||
def setUp(self):
|
||||
super(TestDisabledXBlockTypes, self).setUp()
|
||||
|
||||
for store in self.store.modulestores:
|
||||
store.disabled_xblock_types = ('video',)
|
||||
XBlockConfiguration(name='video', enabled=False).save()
|
||||
|
||||
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
|
||||
def test_get_item(self, default_ms):
|
||||
@@ -2240,15 +2237,27 @@ class TestDisabledXBlockTypes(ModuleStoreTestCase):
|
||||
"""Tests that the list of disabled xblocks can dynamically update."""
|
||||
with self.store.default_store(default_ms):
|
||||
course = CourseFactory()
|
||||
self._verify_descriptor('problem', course, 'CapaDescriptorWithMixins')
|
||||
item_usage_id = self._verify_descriptor('problem', course, 'CapaDescriptorWithMixins')
|
||||
XBlockConfiguration(name='problem', enabled=False).save()
|
||||
self._verify_descriptor('problem', course, 'RawDescriptorWithMixins')
|
||||
|
||||
def _verify_descriptor(self, category, course, descriptor):
|
||||
# First verify that the cached value is used until there is a new request cache.
|
||||
self._verify_descriptor('problem', course, 'CapaDescriptorWithMixins', item_usage_id)
|
||||
|
||||
# Now simulate a new request cache.
|
||||
self.store.request_cache.data = {}
|
||||
self._verify_descriptor('problem', course, 'RawDescriptorWithMixins', item_usage_id)
|
||||
|
||||
def _verify_descriptor(self, category, course, descriptor, item_id=None):
|
||||
"""
|
||||
Helper method that gets an item with the specified category from the
|
||||
modulestore and verifies that it has the expected descriptor name.
|
||||
|
||||
Returns the item's usage_id.
|
||||
"""
|
||||
item = ItemFactory(category=category, parent=course)
|
||||
item = self.store.get_item(item.scope_ids.usage_id)
|
||||
if not item_id:
|
||||
item = ItemFactory(category=category, parent=course)
|
||||
item_id = item.scope_ids.usage_id
|
||||
|
||||
item = self.store.get_item(item_id)
|
||||
self.assertEqual(item.__class__.__name__, descriptor)
|
||||
return item_id
|
||||
|
||||
@@ -1346,7 +1346,7 @@ class ProgressPageTests(ModuleStoreTestCase):
|
||||
self.assertContains(resp, u"Download Your Certificate")
|
||||
|
||||
@ddt.data(
|
||||
*itertools.product(((47, 4, True), (47, 4, False)), (True, False))
|
||||
*itertools.product(((48, 4, True), (48, 4, False)), (True, False))
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_query_counts(self, (sql_calls, mongo_calls, self_paced), self_paced_enabled):
|
||||
|
||||
@@ -372,8 +372,8 @@ class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet
|
||||
return inner
|
||||
|
||||
@ddt.data(
|
||||
(ModuleStoreEnum.Type.mongo, 3, 4, 31),
|
||||
(ModuleStoreEnum.Type.split, 3, 13, 31),
|
||||
(ModuleStoreEnum.Type.mongo, 3, 4, 32),
|
||||
(ModuleStoreEnum.Type.split, 3, 13, 32),
|
||||
)
|
||||
@ddt.unpack
|
||||
@count_queries
|
||||
@@ -381,8 +381,8 @@ class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet
|
||||
self.create_thread_helper(mock_request)
|
||||
|
||||
@ddt.data(
|
||||
(ModuleStoreEnum.Type.mongo, 3, 3, 25),
|
||||
(ModuleStoreEnum.Type.split, 3, 10, 25),
|
||||
(ModuleStoreEnum.Type.mongo, 3, 3, 26),
|
||||
(ModuleStoreEnum.Type.split, 3, 10, 26),
|
||||
)
|
||||
@ddt.unpack
|
||||
@count_queries
|
||||
|
||||
@@ -341,9 +341,14 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
|
||||
MODULESTORE = TEST_DATA_MONGO_MODULESTORE
|
||||
|
||||
@ddt.data(
|
||||
# old mongo with cache
|
||||
(ModuleStoreEnum.Type.mongo, 1, 6, 4, 17, 8),
|
||||
(ModuleStoreEnum.Type.mongo, 50, 6, 4, 17, 8),
|
||||
# Old mongo with cache. There is an additional SQL query for old mongo
|
||||
# because the first time that disabled_xblocks is queried is in call_single_thread,
|
||||
# vs. the creation of the course (CourseFactory.create). The creation of the
|
||||
# course is outside the context manager that is verifying the number of queries,
|
||||
# and with split mongo, that method ends up querying disabled_xblocks (which is then
|
||||
# cached and hence not queried as part of call_single_thread).
|
||||
(ModuleStoreEnum.Type.mongo, 1, 6, 4, 18, 8),
|
||||
(ModuleStoreEnum.Type.mongo, 50, 6, 4, 18, 8),
|
||||
# split mongo: 3 queries, regardless of thread response size.
|
||||
(ModuleStoreEnum.Type.split, 1, 3, 3, 17, 8),
|
||||
(ModuleStoreEnum.Type.split, 50, 3, 3, 17, 8),
|
||||
|
||||
@@ -380,7 +380,9 @@ class TestGetModuleScore(LoginEnrollmentTestCase, SharedModuleStoreTestCase):
|
||||
"""
|
||||
Test test_get_module_score
|
||||
"""
|
||||
with self.assertNumQueries(1):
|
||||
# One query is for getting the list of disabled XBlocks (which is
|
||||
# then stored in the request).
|
||||
with self.assertNumQueries(2):
|
||||
score = get_module_score(self.request.user, self.course, self.seq1)
|
||||
self.assertEqual(score, 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user