Jump to content

Slow Async / Await Functions with TypeORM


Recommended Posts

Posted

Hello,

I've integrated TypeORM and TypeScript into my gamemode to avoid writing SQL queries. However, loading and saving entities from and into the database is very slow and I do not know why. It seems that async calls are blocking for some reason.

async function bootstrap() {
    const connection = await createConnection({
        host: "localhost",
        port: 5432,
        database: "rage",
        username: "rage",
        password: "rage",
        type: "postgres",
        entities: [User, Vehicle],
        synchronize: true,
        logging: true,
    });

    mp.events.addCommand("veh", async (player: PlayerMp, fullText: string) => {
        const vehicle: VehicleMp = mp.vehicles.new(mp.joaat(fullText), player.position);

        const dbVehicle = new Vehicle();
        dbVehicle.model = vehicle.model;
        dbVehicle.position = vehicle.position;
        await connection.manager.save(dbVehicle);
        player.putIntoVehicle(vehicle, -1);
    });

}

bootstrap();

 

Does anybody know why storing entities into the database take so much time? Any help is appreciated :)

  • Like 1
  • Sad 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...