Postgres deadlock

System Information
  • Strapi Version: 4.23.1
  • Operating System: ubuntu
  • Database: postgresql
  • Node Version: no clue
  • NPM Version: no clue
  • Yarn Version: no clue

I wrote a custom updater for a Product collection:

async manualUpdater(ctx) {
    const {products} = ctx.request.body;

    try {
      let notFound = []
      let updates = 0

      await Promise.all(products.map(async (product: { sku: string; stockingStatus: string; allowedForSale: boolean; pricedPer: string; weee: boolean; title: string; slug: string; shortDescription:string; collection: string, categories: number }) => {
        let existingProd = await strapi.db.query("api::product.product").findOne({
          where: {sku: product.sku},
        })

        if (existingProd) {
          await strapi.db.query('api::product.product').update({
            where: { sku: product.sku },
            data: {...product},
          })

          updates++
        } else {
          notFound = [...notFound, product.sku]
        }
      }))
      ctx.send({message: "update successful", updated: updates, notFound: notFound})
    } catch (error) {
      console.error(error)
      ctx.throw(500, "error updater", {error})
    }
  },

If I try to update the categories, which is a relation to “Category” collection, one product works, but with multiple products (3 or more) I keep getting deadlocks

example of what I’m sending to manualUpdater

{
  "products": [
    {"sku": "HDHB06200W160", "categories": 48}
  ]
}

Am I doing this wrong?