DEV: Refactor logic for populating AssetFinder caches

Now populate_cache actually handles the population, and spawn_asset is non-public, i.e. _spawn_asset
This commit is contained in:
Andrew Daniels
2015-06-25 10:18:18 -04:00
parent 46e7b06991
commit 60418f931d
+9 -9
View File
@@ -242,12 +242,17 @@ class AssetFinder(object):
self.identifier_cache = {}
self.fuzzy_match = {}
counter = 0
for identifier, row in self.metadata_cache.items():
self.spawn_asset(identifier=identifier, **row)
counter += 1
asset = self._spawn_asset(identifier=identifier, **row)
def spawn_asset(self, identifier, **kwargs):
# Insert asset into the various caches
self.cache[asset.sid] = asset
self.identifier_cache[identifier] = asset
if asset.symbol is not '':
self.sym_cache.setdefault(asset.symbol, []).append(asset)
def _spawn_asset(self, identifier, **kwargs):
# Check if the sid is declared
try:
@@ -331,11 +336,6 @@ class AssetFinder(object):
else:
raise InvalidAssetType(asset_type=asset_type)
self.cache[asset.sid] = asset
self.identifier_cache[identifier] = asset
if asset.symbol is not '':
self.sym_cache.setdefault(asset.symbol, []).append(asset)
return asset
@property