feat: Turn ON the storage backing for cache by default.

Any places where the storage backing cache for block structures was on
conditionally previously it will be ON by default.
This commit is contained in:
Feanil Patel
2024-07-25 15:15:42 -04:00
parent 3a535d8eca
commit 16d440a4e9

View File

@@ -120,13 +120,12 @@ class BlockStructureStore:
Returns whether the data in storage for the given key is Returns whether the data in storage for the given key is
already up-to-date with the version in the given modulestore. already up-to-date with the version in the given modulestore.
""" """
if config.STORAGE_BACKING_FOR_CACHE.is_enabled(): try:
try: bs_model = self._get_model(root_block_usage_key)
bs_model = self._get_model(root_block_usage_key) root_block = modulestore.get_item(root_block_usage_key)
root_block = modulestore.get_item(root_block_usage_key) return self._version_data_of_model(bs_model) == self._version_data_of_block(root_block)
return self._version_data_of_model(bs_model) == self._version_data_of_block(root_block) except BlockStructureNotFound:
except BlockStructureNotFound: pass
pass
return False return False
@@ -134,26 +133,20 @@ class BlockStructureStore:
""" """
Returns the model associated with the given key. Returns the model associated with the given key.
""" """
if config.STORAGE_BACKING_FOR_CACHE.is_enabled(): return BlockStructureModel.get(root_block_usage_key)
return BlockStructureModel.get(root_block_usage_key)
else:
return StubModel(root_block_usage_key)
def _update_or_create_model(self, block_structure, serialized_data): def _update_or_create_model(self, block_structure, serialized_data):
""" """
Updates or creates the model for the given block_structure Updates or creates the model for the given block_structure
and serialized_data. and serialized_data.
""" """
if config.STORAGE_BACKING_FOR_CACHE.is_enabled(): root_block = block_structure[block_structure.root_block_usage_key]
root_block = block_structure[block_structure.root_block_usage_key] bs_model, _ = BlockStructureModel.update_or_create(
bs_model, _ = BlockStructureModel.update_or_create( serialized_data,
serialized_data, data_usage_key=block_structure.root_block_usage_key,
data_usage_key=block_structure.root_block_usage_key, **self._version_data_of_block(root_block)
**self._version_data_of_block(root_block) )
) return bs_model
return bs_model
else:
return StubModel(block_structure.root_block_usage_key)
def _add_to_cache(self, serialized_data, bs_model): def _add_to_cache(self, serialized_data, bs_model):
""" """
@@ -186,9 +179,6 @@ class BlockStructureStore:
Raises: Raises:
BlockStructureNotFound if not found. BlockStructureNotFound if not found.
""" """
if not config.STORAGE_BACKING_FOR_CACHE.is_enabled():
raise BlockStructureNotFound(bs_model.data_usage_key)
return bs_model.get_serialized_data() return bs_model.get_serialized_data()
def _serialize(self, block_structure): def _serialize(self, block_structure):
@@ -228,12 +218,7 @@ class BlockStructureStore:
Returns the cache key to use for the given Returns the cache key to use for the given
BlockStructureModel or StubModel. BlockStructureModel or StubModel.
""" """
if config.STORAGE_BACKING_FOR_CACHE.is_enabled(): return str(bs_model)
return str(bs_model)
return "v{version}.root.key.{root_usage_key}".format(
version=str(BlockStructureBlockData.VERSION),
root_usage_key=str(bs_model.data_usage_key),
)
@staticmethod @staticmethod
def _version_data_of_block(root_block): def _version_data_of_block(root_block):