Skip to content

Commit 6f9c911

Browse files
committed
update README.md
1 parent 272c896 commit 6f9c911

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

README.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
django-transactions-tutorial 基本教學 - 了解 transactions 概念 📝
44

5+
分支 [django_4_postgresql](https://github.com/twtrubiks/django-transactions-tutorial/tree/django_4_postgresql) 有 django 4 以及 pg 的版本.
6+
57
* [Youtube Tutorial PART 1 - Django 如何連結 MySQL](https://youtu.be/0IKuKk8ubf0)
68
* [Youtube Tutorial PART 2 - Transaction 概念簡介](https://youtu.be/P67IfMK4Y5g)
79
* [Youtube Tutorial PART 3 - Django 實戰 Transaction - Atomicity](https://youtu.be/aG33kaSmgzI)
@@ -220,6 +222,8 @@ def create_items_no_transaction(**kwargs):
220222

221223
如下圖,你會發現,有四筆資料進資料庫了 ( 而且一筆資料還是錯的 ),
222224

225+
(有些資料庫你會發現只寫進 3 筆而已, 因為第 4 筆開始發生錯誤)
226+
223227
![alt tag](https://i.imgur.com/dz0uW2E.png)
224228

225229
他也違反了ACID 的原則,應該全部的資料都不能進資料庫,也就是好像什麼事情都沒發生過一樣。
@@ -392,9 +396,9 @@ Returns a queryset that will lock rows until the end of the transaction, generat
392396

393397
主要就是透過 SQL 中的 `SELECT ... FOR UPDATE` 語法將目前的 row 鎖定,必須等他交易結束,
394398

395-
其他的人才可以使用這個 row,這邊也要注意,要看 databases 有沒有支援這個語法,像是 [MySQL](https://www.mysql.com/cn/)
399+
其他的人才可以使用這個 row,這邊也要注意,要看 databases 有沒有支援這個語法,
396400

397-
以及 [PostgreSQL](https://www.postgresql.org/) 就有支援,[SQLite](https://www.sqlite.org/index.html) 則沒有支援。
401+
像是 [MySQL](https://www.mysql.com/cn/) 以及 [PostgreSQL](https://www.postgresql.org/) 就有支援,[SQLite](https://www.sqlite.org/index.html) 則沒有支援。
398402

399403
透過這個方法,
400404

@@ -469,7 +473,7 @@ def data_consistency():
469473
return 200
470474
```
471475

472-
Optimistic 方法,這邊提供兩種方法給大家,其中一種是增加一個欄位去追蹤目前的變化 ( version 這個欄位 ),
476+
這邊提供兩種方法給大家,其中一種是增加一個欄位去追蹤目前的變化 ( version 這個欄位 ),
473477

474478
每次都會將 version 帶入查詢條件,並且如果成功更新,就加一 ; 另一種方法是不增加一個欄位,直接將 stock
475479

@@ -493,9 +497,13 @@ else:
493497

494498
### Pessimistic vs Optimistic
495499

496-
如果你的系統同時間會有很高的機率同時修改一筆資料,適合使用 Pessimistic 的方法。
500+
如果你的系統同時間會有很高的機率同時修改一筆資料,
501+
502+
適合使用 Pessimistic (悲觀) 的方法。
503+
504+
如果你的系統同時間修改一筆資料的機率非常低或是使用者較少以及大部分都是讀取的操作,
497505

498-
如果你的系統同時間修改一筆資料的機率非常低或是使用者較少以及大部分都是讀取的操作,適合使用 Optimistic 的方法。
506+
適合使用 Optimistic (樂觀) 的方法。
499507

500508
## 後記
501509

@@ -520,6 +528,14 @@ else:
520528
* [How to manage concurrency in Django models](https://medium.com/@hakibenita/how-to-manage-concurrency-in-django-models-b240fed4ee2)
521529
* [PESSIMISTIC vs. OPTIMISTIC concurrency control](https://www.ibm.com/support/knowledgecenter/en/SSPK3V_7.0.0/com.ibm.swg.im.soliddb.sql.doc/doc/pessimistic.vs.optimistic.concurrency.control.html)
522530

531+
## Donation
532+
533+
文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡:laughing:
534+
535+
![alt tag](https://i.imgur.com/LRct9xa.png)
536+
537+
[贊助者付款](https://payment.opay.tw/Broadcaster/Donate/9E47FDEF85ABE383A0F5FC6A218606F8)
538+
523539
## License
524540

525541
MIT license

0 commit comments

Comments
 (0)