Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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?

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
kwi 16
3893
0
lut 19
5194
2
sie 25
2442
2
cze 25
820
3
cze 24
3615