Is doing Transaction Management in the Controller bad practice?

前端 未结 4 1849
情深已故
情深已故 2021-01-31 19:00

I\'m working on a PHP/MySQL app using the Yii framework.

I\'ve come across the following situation:

In my VideoController, I have a actionCrea

4条回答
  •  甜味超标
    2021-01-31 19:36

    Well, one disadvantage of these broad transactions (over the whole request) is that you limit concurrency capabilities of your database engine and you also increase deadlocks probability. From this point of view, it might pay off to put transactions only where you need them and let them cover only code that needs to be covered.

    If possible, I would definitely go for placing transaction in models. The problem with overlapping transactions can be solved by introducing BaseModel (ancestors of all models) and variable transactionLock in that model. Then you simply wrap your begin/commit transaction directives into BaseModel methods that respect this variable.

提交回复
热议问题