Open
Conversation
Owner
|
ありがとうございます!暗号が14個配布されてしまう問題はこのlockが原因な気もします...ソースコードを確認してからコミットしたいと思っております!お時間がかかります...すみません |
Owner
|
(大変お時間空けてしまって申し訳ありません) |
Contributor
Author
|
無駄にデカイPRに目を通していただいてありがとうございます。また一部取り込んでいただきありがとうございました 🙇 ちなみに PR は close しても残りますし close した後で必要になれば reopen(再度open状態にすること) も可能なので、これぐらい処遇が決まっていれば個人的には close にしてしまっても良いかなと思いました。(細かいことなのでご対応はお任せします) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQLite から Postgresql に変わったことで同時書き込みエラーが減り、同時更新による二重加算やロストアップデートなどのデータ不整合が顕在化してきているのではないかという気がしていますが、いかがでしょうか
スコア計算の変更でデータ不整合の問題が無くなっているようであれば、このPRは無視してください
ロストアップデートというのは前の更新を後の更新で上書きしてしまうことです
参考: https://qiita.com/tikamoto/items/f867050ff77d06a94215#ロストアップデートが起こる例
二重加算も二重リクエストなどで更新済みフラグを同時に読んでしまって両方の更新処理が通ってしまうなどすると発生します
こういったデータ不整合を防ぐにはロックを使う必要があります
参考: https://qiita.com/tikamoto/items/f867050ff77d06a94215#ロストアップデートを防ぐ
ということでこのPRでは transaction を使うのと select for update によるロックを入れてみました
これの対応をするにあたって以下の理由で view での更新がネックになるので controller や model にその処理を移動させたりもしています
テストがなく
トップページ摘発摘発履歴あたりの画面を目視確認しただけなので、これを適用して問題があったとき責任が取れないので、適用する場合はよくよく開発環境での確認のうえ慎重にお願いしますデータ不整合対策の参考にして頂ければ幸いです