(
self, collection: AsyncCollection[Any], index_key: Any, unique: bool
)
| 1172 | object.__setattr__(self, "_buffered_docs_size", 0) |
| 1173 | |
| 1174 | async def _create_index( |
| 1175 | self, collection: AsyncCollection[Any], index_key: Any, unique: bool |
| 1176 | ) -> None: |
| 1177 | doc = await collection.find_one(projection={"_id": 1}, session=self._session) |
| 1178 | if doc is None: |
| 1179 | try: |
| 1180 | index_keys = [ |
| 1181 | index_spec["key"] |
| 1182 | async for index_spec in await collection.list_indexes(session=self._session) |
| 1183 | ] |
| 1184 | except OperationFailure: |
| 1185 | index_keys = [] |
| 1186 | if index_key not in index_keys: |
| 1187 | await collection.create_index( |
| 1188 | index_key.items(), unique=unique, session=self._session |
| 1189 | ) |
| 1190 | |
| 1191 | async def _ensure_indexes(self) -> None: |
| 1192 | if not object.__getattribute__(self, "_ensured_index"): |
no test coverage detected