Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3572 Visualizzazioni

Hello,

I am in the process of building a controller which has multiple endpoints. Sometimes 2 endpoints are called within milliseconds of each other, these endpoints will create a customer if one doesn't already exist in the database. I tried to use time.sleep() to delay one of the threads but I have realised that the request.env variable does not get notified/updated when a process is carried out on another env variable. 

Is there any way to update the environment in a sense?

I see two other ways of potentially doing this which are:

  1. Querying the database directly with SQL commands

  2. Creating the data in a custom model which will then be picked up by a Cron job so they are all on the same thread, thus the same environment. 

Both of these options create a bit more work than I would like compared to finding a way to update the environment. 

Any suggestions would be greatly appreciated.

Thanks, 

EDIT: 

When I run: env.cr.commit() it seems to work but after reading this I am not sure whether this would be safe. 

When I start with env.cr.autocommit(True) this seems to work as well and I am not manually committing each time, could anyone spread some light on any risks related to cr.autocommit?

Or is only turned off by default to save on speed and memory?

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
apr 16
3903
0
feb 19
5202
2
ago 25
2444
2
giu 25
825
3
giu 24
3617