Fix cache

This commit is contained in:
2023-06-01 14:10:50 +02:00
parent 177abadd2a
commit 63d8cd8628

View File

@@ -107,13 +107,23 @@ async def cache_file(book: Book, file_type: str) -> Optional[CachedFile]:
if upload_data is None: if upload_data is None:
return None return None
return await CachedFile.objects.create( cached_file, created = await CachedFile.objects.get_or_create(
{
"message_id": upload_data.data["message_id"],
"chat_id": upload_data.data["chat_id"],
},
object_id=book.id, object_id=book.id,
object_type=file_type, object_type=file_type,
message_id=upload_data.data["message_id"],
chat_id=upload_data.data["chat_id"],
) )
if created:
return cached_file
cached_file.message_id = upload_data.data["message_id"]
cached_file.chat_id = upload_data.data["chat_id"]
return await cached_file.update(["message_id", "chat_id"])
@broker.task(retry_on_error=True) @broker.task(retry_on_error=True)
async def cache_file_by_book_id( async def cache_file_by_book_id(