async def index_keys(self, index_name, index_key): async with self._lock: if index_name not in self._indexers: raise KeyError(f"Index with name {index_name} does not exist") index = self._indices.get(index_name, _index.Index()) set_ = index.get(index_key, set()) return list(set_)
def _update_indices(self, old_obj, new_obj, key): if old_obj is not None: self._delete_from_indices(old_obj, key) for name, index_func in self._indexers.items(): index_values = index_func(new_obj) index = self._indices.setdefault(name, _index.Index()) for index_value in index_values: set_ = index.setdefault(index_value, set()) set_.add(key)
async def index(self, index_name, obj): async with self._lock: index_func = self._indexers[index_name] index_keys = index_func(obj) index = self._indices.get(index_name, _index.Index()) if len(index_keys) == 1: return_key_set = index.get(index_keys[0], set()) else: return_key_set = { key for index_key in index_keys for key in index.get(index_key, set()) } return [ self._items[absolute_key] for absolute_key in return_key_set ]
async def list_index_func_values(self, index_name): async with self._lock: index = self._indices.get(index_name, _index.Index()) names = list(index) return names