跳至内容
菜单
此问题已终结

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?

形象
丢弃
相关帖文 回复 查看 活动
0
4月 16
3901
0
2月 19
5201
2
8月 25
2444
2
6月 25
824
3
6月 24
3616