@@ -261,13 +261,12 @@ async def index_files(self) -> dict[str, str]:
261
261
def filehash (body : str ) -> str :
262
262
return hexdigest (body )
263
263
264
- async def filecheck (self , filename : str , body : str | None = None ) -> bool :
264
+ async def filecheck (self , filename : str , body_filehash : str | None = None ) -> bool :
265
265
"""Check if this index contains the filename and if the body's filehash matches."""
266
- filehash : str | None = self .filehash (body ) if body else None
267
266
index_files = await self .index_files
268
267
return bool (
269
268
index_files .get (filename )
270
- and (filehash is None or index_files [filename ] == filehash )
269
+ and (body_filehash is None or index_files [filename ] == body_filehash )
271
270
)
272
271
273
272
async def mark_failed_document (self , path : str | os .PathLike ) -> None :
@@ -297,19 +296,20 @@ async def add_document(
297
296
retry = retry_if_exception_type (AsyncRetryError ),
298
297
)
299
298
async def _add_document () -> None :
300
- if not await self .filecheck (index_doc ["file_location" ], index_doc ["body" ]):
299
+ body_filehash = self .filehash (index_doc ["body" ])
300
+ if not await self .filecheck (index_doc ["file_location" ], body_filehash ):
301
301
try :
302
302
async with self .writer () as writer :
303
303
# Let caller handle commit to allow for batching
304
304
writer .add_document (Document .from_dict (index_doc ))
305
305
306
- filehash = self .filehash (index_doc ["body" ])
307
- (await self .index_files )[index_doc ["file_location" ]] = filehash
306
+ (await self .index_files )[index_doc ["file_location" ]] = body_filehash
308
307
309
308
if document :
310
309
docs_index_dir = await self .docs_index_directory
311
310
async with await anyio .open_file (
312
- docs_index_dir / f"{ filehash } .{ self .storage .extension ()} " ,
311
+ docs_index_dir
312
+ / f"{ body_filehash } .{ self .storage .extension ()} " ,
313
313
"wb" ,
314
314
) as f :
315
315
await f .write (self .storage .write_to_string (document ))
0 commit comments