By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This produces a deadlock most times I run it. I am looping around an array to update each one. I tried the solution found on issue #551 but that didn't help any.

async updateSeriesCategoryOrder(entityManager: EntityManager, organisationId: number, raceMeetId: number, idArray: number[]): Promise<void> {
        for ( let i = 0; i < idArray.length; i++ ) {
            const raceMeetSeriesCategoryId = raceMeetSeriesCategoryIdArrayInOrder[i];
            const raceMeetSeriesCategoryDB: RaceMeetSeriesCategory = await this.raceMeetSeriesCategoryRepository.findOneByRaceMeetSeriesCategoryIdAndOrganisationId(entityManager, organisationId, raceMeetSeriesCategoryId);
            if (!raceMeetSeriesCategoryDB)
                throw new InvalidIdError();
            entityManager
                .createQueryBuilder(RaceMeetSeriesCategory, "raceMeetSeriesCategory")
                .update({
                    categoryOrder: categoryOrder
                .where("raceMeetSeriesCategory.id = :raceMeetSeriesCategoryId")
                .setParameter("raceMeetSeriesCategoryId", raceMeetSeriesCategoryId)
                .execute();
          

you have exactly same problem as in #551 - you are not awaiting promises. Put await before entityManager...execute():

async updateSeriesCategoryOrder(entityManager: EntityManager, organisationId: number, raceMeetId: number, idArray: number[]): Promise<void> {
        for ( let i = 0; i < idArray.length; i++ ) {
            const raceMeetSeriesCategoryId = raceMeetSeriesCategoryIdArrayInOrder[i];
            const raceMeetSeriesCategoryDB: RaceMeetSeriesCategory = await this.raceMeetSeriesCategoryRepository.findOneByRaceMeetSeriesCategoryIdAndOrganisationId(entityManager, organisationId, raceMeetSeriesCategoryId);
            if (!raceMeetSeriesCategoryDB)
                throw new InvalidIdError();
            await entityManager
                .createQueryBuilder(RaceMeetSeriesCategory, "raceMeetSeriesCategory")
                .update({
                    categoryOrder: categoryOrder
                .where("raceMeetSeriesCategory.id = :raceMeetSeriesCategoryId")
                .setParameter("raceMeetSeriesCategoryId", raceMeetSeriesCategoryId)
                .execute();