Advice on how to handle asynchronous operations for a code snippet in python for firebase database CRUD operations

I need advice regarding a code snippet for python.

@firestore_fn.on_document_created(document=r"UserDeletes/{id}")
async def delete_user(event: firestore_fn.Event[firestore_fn.DocumentSnapshot | None]) -> None:
    adminpass = firebase_admin.auth
    database_updates_before_deletion = firestore.client()

    #delete STORAGE items of user
    databasephotos.bucket(f'profileImage/${event.data.get('userid')}').delete(force=True)
    databasephotos.bucket(f'bannerImage/${event.data.get('userid')}').delete(force=True)
    databasephotos.bucket(f'Audios/${event.data.get('textid')}/${event.data.get('userid')}').delete(force=True)
    databasephotos.bucket(f'AudiosSamples/${event.data.get('textid')}/${event.data.get('userid')}').delete(force=True)

    #delete all DOCUMENT audios from user
    audios_to_delete = database_updates_before_deletion.collection('Audios').where(filter=FieldFilter('userid', '==', event.data.get('userid') )).get()
    for doc in audios_to_delete:
        await database_updates_before_deletion.collection('Audios').document(f'{doc.to_dict().get('id')}').delete()
    
    audios_to_delete = database_updates_before_deletion.collection('SampleAudios').where(filter=FieldFilter('userid', '==', event.data.get('userid') )).get()
    for doc in audios_to_delete:
        await database_updates_before_deletion.collection('SampleAudios').document(f'{doc.to_dict().get('id')}').delete()

        

    #get all texts to update, where the user deleted was the lastest narrator.
    texts_to_update = await database_updates_before_deletion.collection('Texts').where(filter=FieldFilter('latestnarratorid', '==', event.data.get('userid'))).get()
    if(len(texts_to_update) != 0):
        #for every texts found
        for doc in texts_to_update:
            #get a different audio from the collection of narrations that the text has available
            audio_replace = await database_updates_before_deletion.collection('Audios').where(FieldFilter('textid', '==', event.data.get('textid'))).limit(1).get()
            #if one is found, get values needed. Else, the user deleted was the only narrator, so no document of audio was found
            if(len(audio_replace) != 0):
                audio_replace_id =  audio_replace[0].to_dict().get('id')
                audio_replace_name = audio_replace[0].to_dict().get('nameOfnarrator')
                audio_replace_url = audio_replace[0].to_dict().get('urlfromstorage')
                audio_replace_narratorid = audio_replace[0].to_dict().get('userid')
                audio_text_count = audio_replace[0].to_dict().get('audiosCount')
            else:
                #case where user had the last audio narration of a text, update text with empty values.
                audio_replace_id = ''
                audio_replace_name = ''
                audio_replace_url = ''
                audio_replace_narratorid = ''
                audio_text_count = 0
                #update the document
            database_updates_before_deletion.collection('Texts').document(f'${doc.to_dict().get('id')}').update({
                'id': audio_replace_id,
                'nameOfnarrator': audio_replace_name,
                'urlfromstorage': audio_replace_url,
                'userid':audio_replace_narratorid,
                'audiosCount' : audio_text_count - 1,
            })
    

    #finally, delete user
    the_user_id_to_delete = event.data.get('userid')
    adminpass.delete_user(the_user_id_to_delete)

    return

The goal is to delete all audios and storage that the user has, once the user decides to delete its profile. The method is run by firebase functions services.

I need a little advice on how to handle the asynchronous operation for the method.

My application lets users narrates parts of sermons written by preachers. I have it so that when a user uploads a audio, and it is approved, it will become the latest narration available. So when another user opens the text, that audio will be the first one available and ready to play.

When users decide to delete their account, I need to replace the latest narration with any other audio available for that text. If the user that decided to delete the account, was the only narrator, then the text will have 0 audios available, so a different User Interface for the text will be displayed when that happens.

I have little experience with python so I would appreciate a little feedback regarding how to handle the async await operations. Thank you.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật