Prevent race condition

This commit is contained in:
jasonkhew96 2021-05-04 20:43:34 +08:00 committed by BennyThink
parent 50263b8cad
commit a783709355
No known key found for this signature in database
GPG key ID: 6CD0DBDA5235D481

View file

@ -38,17 +38,17 @@ async def upload_callback(current, total, chat_id, message):
key = f"{chat_id}-{message.id}"
# if the key exists, we shouldn't send edit message
if not r.exists(key):
r.set(key, "ok", ex=EXPIRE)
msg = f'Uploading {round(current / total * 100, 2)}%: {current}/{total}'
await bot.edit_message(chat_id, message, msg)
r.set(key, "ok", ex=EXPIRE)
async def sync_edit_message(chat_id, message, msg):
# try to avoid flood
key = f"{chat_id}-{message.id}"
if not r.exists(key):
await bot.edit_message(chat_id, message, msg)
r.set(key, "ok", ex=EXPIRE)
await bot.edit_message(chat_id, message, msg)
def go(chat_id, message, msg):