def get_asset_data( asset_identifier: str, form_with_incomplete_data: bool = False, ) -> AssetData: """Get all asset data for a valid asset identifier Raises UnknownAsset if no data can be found """ instance = AssetResolver() # attempt read from memory cache -- always lower cached_data = instance.assets_cache.get(asset_identifier.lower(), None) if cached_data is not None: return cached_data check_json = False try: dbinstance = GlobalDBHandler() if dbinstance.get_setting_value('last_assets_json_version', 0) == 0: check_json = True except ModuleInitializationFailure: check_json = True if check_json: # still need to resolve out of the in memory all_assets.json if instance.all_assets is None: raise AssertionError( 'We need to check all_assets.json and cached data has been deleted', ) result = instance.all_assets.get(asset_identifier, None) if result is None: raise UnknownAsset(asset_identifier) return result # At this point we can use the global DB asset_data = dbinstance.get_asset_data(asset_identifier, form_with_incomplete_data) if asset_data is None: raise UnknownAsset(asset_identifier) # save in the memory cache -- always lower instance.assets_cache[asset_identifier.lower()] = asset_data return asset_data
def get_asset_data( asset_identifier: str, form_with_incomplete_data: bool = False, ) -> AssetData: """Get all asset data for a valid asset identifier Raises UnknownAsset if no data can be found """ instance = AssetResolver() # attempt read from memory cache -- always lower cached_data = instance.assets_cache.get(asset_identifier.lower(), None) if cached_data is not None: return cached_data dbinstance = GlobalDBHandler() # At this point we can use the global DB asset_data = dbinstance.get_asset_data(asset_identifier, form_with_incomplete_data) if asset_data is None: raise UnknownAsset(asset_identifier) # save in the memory cache -- always lower instance.assets_cache[asset_identifier.lower()] = asset_data return asset_data