def reload(self): """Populate all of the ID-name elements and return this object. """ all_models = self._dao_method() by_id = collections.defaultdict(set) all_elms = set() for model in all_models: elm = id_name_elm_from_model(model) by_id[elm.id].add(elm) all_elms.add(elm) self._by_id = get_frozen_mapping(by_id) self._all = frozenset(all_elms) # Check if DEBUG is enabled since getting memory usage is slow if self._logger.isEnabledFor(logging.DEBUG): self._logger.debug( '%s by ID using %s mb', self.__class__.__name__, avalon.util.get_size_in_mb(self._by_id)) self._logger.debug( '%s all elements using %s mb', self.__class__.__name__, avalon.util.get_size_in_mb(self._all)) return self
def _get_name_id_map(all_models): """Get the name to ID mappings for a particular type of entity, normalizing the case of the name value using a default dictionary configured to return None for missing entries. """ mapping = collections.defaultdict(lambda: None) for model in all_models: elm = id_name_elm_from_model(model) mapping[elm.name.lower()] = elm.id return mapping